fix: add verif for sleeping and not only for eating

This commit is contained in:
Camille Chauvet 2023-04-20 12:21:03 +00:00
parent 19c5a53ba9
commit caa4491fbb

12
main.c
View File

@ -3,6 +3,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include "./philos.h" #include "./philos.h"
#include "./data.h" #include "./data.h"
#include "./parsing.h" #include "./parsing.h"
@ -70,8 +71,19 @@ void *check_routine(t_data *data)
stop(data); stop(data);
return (NULL); 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++; i++;
} }
usleep(100);
} }
} }