Compare commits

..

2 Commits

Author SHA1 Message Date
Camille Chauvet
531d3146e4 merge 2023-04-25 11:30:55 +00:00
Camille Chauvet
b553e5af97 fix: stop when philo has enough eat 2023-04-20 13:16:02 +00:00
2 changed files with 7 additions and 8 deletions

2
data.c
View File

@ -11,6 +11,7 @@
bool data_init(t_data *data)
{
data->stop = 0;
data->forks = malloc(sizeof(bool) * data->nb_philos);
if (data->forks == NULL)
return (1);
@ -31,7 +32,6 @@ bool data_init(t_data *data)
pthread_mutex_init(&data->forks_mutex, NULL);
pthread_mutex_init(&data->stop_mutex, NULL);
pthread_mutex_init(&data->print_mutex, NULL);
data->stop = 0;
return (0);
}

13
main.c
View File

@ -52,12 +52,6 @@ void *check_routine(t_data *data)
while (true)
{
if ((ssize_t) get_min_meal(data) == data->nb_meals)
{
stop(data);
printf("g pu faim\n");
return (NULL);
}
i = 0;
while (i < data->nb_philos)
{
@ -82,7 +76,12 @@ void *check_routine(t_data *data)
return (NULL);
}
i++;
usleep(10);
if ((ssize_t) get_min_meal(data) >= data->nb_meals)
{
stop(data);
printf("g pu faim\n");
return (NULL);
}
}
}
}