From caa4491fbbb3e38fdbbf7b525e64708953352e42 Mon Sep 17 00:00:00 2001 From: Camille Chauvet Date: Thu, 20 Apr 2023 12:21:03 +0000 Subject: [PATCH] fix: add verif for sleeping and not only for eating --- main.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/main.c b/main.c index 3a27dc8..166f308 100644 --- a/main.c +++ b/main.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "./philos.h" #include "./data.h" #include "./parsing.h" @@ -70,8 +71,19 @@ void *check_routine(t_data *data) stop(data); return (NULL); } + pthread_mutex_lock(&philo->last_sleep_mutex); + // printf("time=%zu, last_sleep=%zu, life_expectency=%zu\n", get_time(), philo->last_sleep, data->life_expectency); + ok = !(philo->last_sleep + data->life_expectency > get_time()); + pthread_mutex_unlock(&philo->last_sleep_mutex); + if (ok == 1) + { + print_died(philo); + stop(data); + return (NULL); + } i++; } + usleep(100); } }