From ebbd81e4312d945b359d2761acfeb613da1f98c8 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Sat, 9 Jan 2021 14:40:23 +0100 Subject: Added antidead lock in philo_one --- philo_one/src/event.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'philo_one/src/event.c') diff --git a/philo_one/src/event.c b/philo_one/src/event.c index df621b4..92ca399 100644 --- a/philo_one/src/event.c +++ b/philo_one/src/event.c @@ -6,25 +6,21 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 21:37:50 by cacharle #+# #+# */ -/* Updated: 2021/01/08 18:27:33 by charles ### ########.fr */ +/* Updated: 2021/01/09 13:12:20 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #include "philo_one.h" -void event_take_fork(t_philo *arg) +void event_take_fork(t_philo *arg, pthread_mutex_t *mutex_fork) { if (philo_finished(arg->conf)) return ; - pthread_mutex_lock(arg->fork_left); - pthread_mutex_lock(arg->fork_right); + pthread_mutex_lock(mutex_fork); pthread_mutex_lock(&arg->conf->mutex_stdout); if (philo_finished(arg->conf)) return ; philo_put(arg->id, EVENT_FORK, arg->conf->initial_time); - if (philo_finished(arg->conf)) - return ; - philo_put(arg->id, EVENT_FORK, arg->conf->initial_time); pthread_mutex_unlock(&arg->conf->mutex_stdout); } @@ -39,6 +35,7 @@ void event_eat(t_philo *arg) pthread_mutex_unlock(&arg->conf->mutex_stdout); arg->time_last_eat = h_time_now(); h_sleep(arg->conf->timeout_eat); + arg->time_last_eat = h_time_now(); } void event_think(t_philo *arg) -- cgit