From eb2cfb574efafcf2c3c6200d1cd2de700ec8ddfb Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Sun, 10 Jan 2021 10:54:04 +0100 Subject: Fixing bad performance at school by adding more delay to the death checking loop, Added mutex/semaphore to protect against eating and dying at the same time --- philo_one/src/event.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'philo_one/src/event.c') diff --git a/philo_one/src/event.c b/philo_one/src/event.c index 92ca399..88b9ff1 100644 --- a/philo_one/src/event.c +++ b/philo_one/src/event.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 21:37:50 by cacharle #+# #+# */ -/* Updated: 2021/01/09 13:12:20 by charles ### ########.fr */ +/* Updated: 2021/01/10 09:55:58 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,14 +28,15 @@ void event_eat(t_philo *arg) { if (philo_finished(arg->conf)) return ; + pthread_mutex_lock(&arg->mutex_eat); pthread_mutex_lock(&arg->conf->mutex_stdout); if (philo_finished(arg->conf)) return ; philo_put(arg->id, EVENT_EAT, arg->conf->initial_time); pthread_mutex_unlock(&arg->conf->mutex_stdout); arg->time_last_eat = h_time_now(); + pthread_mutex_unlock(&arg->mutex_eat); h_sleep(arg->conf->timeout_eat); - arg->time_last_eat = h_time_now(); } void event_think(t_philo *arg) -- cgit