From 802ea8347d1ceb7a02cf279359b3b101106fab94 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Sat, 9 Jan 2021 16:07:01 +0100 Subject: Added separate thread to check if max meal num is reached independent from philosopher death --- philo_two/src/event.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'philo_two/src/event.c') diff --git a/philo_two/src/event.c b/philo_two/src/event.c index 3ce471e..2fc1249 100644 --- a/philo_two/src/event.c +++ b/philo_two/src/event.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 21:37:50 by cacharle #+# #+# */ -/* Updated: 2021/01/08 19:54:40 by charles ### ########.fr */ +/* Updated: 2021/01/09 15:18:24 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ void event_take_fork(t_philo *arg) { - sem_wait(arg->forks); + sem_wait(arg->conf->sem_forks); sem_wait(arg->conf->sem_stdout); philo_put(arg->id, EVENT_FORK, arg->conf->initial_time); sem_post(arg->conf->sem_stdout); @@ -40,23 +40,14 @@ void event_sleep(t_philo *arg) sem_wait(arg->conf->sem_stdout); philo_put(arg->id, EVENT_SLEEP, arg->conf->initial_time); sem_post(arg->conf->sem_stdout); - sem_post(arg->forks); - sem_post(arg->forks); + sem_post(arg->conf->sem_forks); + sem_post(arg->conf->sem_forks); h_sleep(arg->conf->timeout_sleep); } void event_die(t_philo *arg) { - long int i; - sem_wait(arg->conf->sem_stdout); philo_put(arg->id, EVENT_DIE, arg->conf->initial_time); - if (arg->conf->meal_num == -1) - sem_post(arg->conf->sem_finish); - else - { - i = -1; - while (++i < arg->conf->philo_num) - sem_post(arg->conf->sem_finish); - } + sem_post(arg->conf->sem_finish); } -- cgit