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); } }