-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
61 lines (54 loc) · 1.73 KB
/
main.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lenzo-pe <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/10 01:41:21 by lenzo-pe #+# #+# */
/* Updated: 2022/03/10 11:26:43 by lenzo-pe ### ########.fr */
/* */
/* ************************************************************************** */
#include "philo.h"
void everyone_getout_together(t_seats *seats)
{
t_seats *ptr;
ptr = seats;
while (42)
{
seats = seats->right;
pthread_join(seats->philo, NULL);
if (seats == ptr)
break ;
}
}
void clean_the_dirty_dishes(t_seats *seats)
{
t_seats *ptr;
ptr = seats;
free(ptr->status);
free(ptr->rules);
while (42)
{
pthread_mutex_destroy(&seats->t_pfork);
seats = seats->right;
if (seats == ptr)
break ;
}
clear_seats(seats);
}
int main(int argc, char **argv)
{
t_seats *seats;
if (you_should_not_pass(argc, argv + 1))
return (EXIT_FAILURE);
seats = NULL;
one_seat_for_each_guest(&seats, my_strtoul(*(argv + 1)));
one_fork_for_each_guest(seats);
guests_profile(seats, argv + 1);
rules_of_the_party(seats, argv + 1);
everyone_lets_party(seats);
everyone_getout_together(seats);
clean_the_dirty_dishes(seats);
return (EXIT_SUCCESS);
}