-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinish.c
61 lines (53 loc) · 1.63 KB
/
finish.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* finish.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vsimeono <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/23 12:03:34 by vsimeono #+# #+# */
/* Updated: 2022/05/25 15:16:17 by vsimeono ### ########.fr */
/* */
/* ************************************************************************** */
#include "philosophers.h"
void destroy_mutexes(t_game *game)
{
int i;
i = 0;
pthread_mutex_destroy(&(game->m_print));
while (i < game->number_of_philos)
{
pthread_mutex_destroy(game->m_forks + i);
pthread_mutex_destroy(&(game->to_philosopher[i]->m_eat));
i++;
}
}
void join_threads(t_game *game, pthread_t *thread)
{
int i;
i = 0;
while (i < game->number_of_philos)
{
pthread_join(thread[i], NULL);
i++;
}
}
void free_philosophers(t_game *game)
{
int i;
i = 0;
while (i < game->number_of_philos)
{
free(game->to_philosopher[i]);
i++;
}
}
void goodnight(t_game *game, pthread_t *thread)
{
join_threads(game, thread);
destroy_mutexes(game);
free_philosophers(game);
free(game->to_philosopher);
free(game->m_forks);
free(thread);
}