Compare commits

..

No commits in common. "531d3146e4da105ce1de39628a8160991b97ec78" and "f51039c735a4926ff5f4f970f2d8295913545568" have entirely different histories.

2 changed files with 8 additions and 7 deletions

2
data.c
View File

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

13
main.c
View File

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