diff --git a/data.h b/data.h index ffd53be..3648656 100644 --- a/data.h +++ b/data.h @@ -9,7 +9,7 @@ typedef struct s_data size_t sleep_time; size_t life_expectency; size_t nb_philos; - ssize_t nb_meals; + size_t nb_meals; void **philos; pthread_t *threads; pthread_mutex_t *forks; diff --git a/main.c b/main.c index 2ba46b8..d49a2f4 100644 --- a/main.c +++ b/main.c @@ -65,12 +65,12 @@ void *check_routine(t_data *data) print_died(philo); return (NULL); } - i++; - if ((ssize_t) get_min_meal(data) == data->nb_meals) + if (get_min_meal(data) >= data->nb_meals) { stop(data); return (NULL); } + i++; } } } diff --git a/philo.c b/philo.c index 3f5f2f0..44a24de 100644 --- a/philo.c +++ b/philo.c @@ -63,6 +63,9 @@ bool philo_eat(t_philo *philo, t_data *data) pthread_mutex_lock(&philo->last_eat_mutex); philo->last_eat = get_time(); pthread_mutex_unlock(&philo->last_eat_mutex); + pthread_mutex_lock(&philo->nb_meal_mutex); + philo->nb_meal++; + pthread_mutex_unlock(&philo->nb_meal_mutex); return (0); } diff --git a/philo.h b/philo.h index 78c0630..b0acc35 100644 --- a/philo.h +++ b/philo.h @@ -6,7 +6,7 @@ /* By: cchauvet