From 69e34424c178a7acfc1264fa4ea0559ae39b2495 Mon Sep 17 00:00:00 2001 From: Camille Chauvet Date: Tue, 25 Apr 2023 14:56:57 +0000 Subject: [PATCH] fix: philo alone died now --- philo.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/philo.c b/philo.c index 44a24de..65424d8 100644 --- a/philo.c +++ b/philo.c @@ -42,6 +42,12 @@ bool philo_eat(t_philo *philo, t_data *data) pthread_mutex_unlock(&data->forks[philo->id]); return (1); } + while ((philo->id + 1) % data->nb_philos == philo->id) + if (check(philo, data)) + { + pthread_mutex_unlock(&data->forks[philo->id]); + return (1); + } pthread_mutex_lock(&data->forks[(philo->id + 1) % data->nb_philos]); print_take_a_fork(philo); if (check(philo, data))