aboutsummaryrefslogtreecommitdiff
path: root/philo_two/src/event.c
diff options
context:
space:
mode:
Diffstat (limited to 'philo_two/src/event.c')
-rw-r--r--philo_two/src/event.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/philo_two/src/event.c b/philo_two/src/event.c
index faf963b..0eaad11 100644
--- a/philo_two/src/event.c
+++ b/philo_two/src/event.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/14 21:37:50 by cacharle #+# #+# */
-/* Updated: 2021/01/01 14:26:02 by charles ### ########.fr */
+/* Updated: 2021/01/01 15:57:43 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -23,6 +23,8 @@ void event_take_fork(t_philo *arg)
if (philo_finished(arg->conf))
return ;
philo_put(arg->id, EVENT_FORK);
+ if (philo_finished(arg->conf))
+ return ;
sem_post(arg->conf->sem_stdout);
}
@@ -34,6 +36,8 @@ void event_eat(t_philo *arg)
if (philo_finished(arg->conf))
return ;
philo_put(arg->id, EVENT_EAT);
+ if (philo_finished(arg->conf))
+ return ;
sem_post(arg->conf->sem_stdout);
usleep(arg->conf->timeout_eat * 1000);
}
@@ -46,6 +50,8 @@ void event_think(t_philo *arg)
if (philo_finished(arg->conf))
return ;
philo_put(arg->id, EVENT_THINK);
+ if (philo_finished(arg->conf))
+ return ;
sem_post(arg->conf->sem_stdout);
}
@@ -57,9 +63,17 @@ void event_sleep(t_philo *arg)
if (philo_finished(arg->conf))
return ;
philo_put(arg->id, EVENT_SLEEP);
+ if (philo_finished(arg->conf))
+ return ;
sem_post(arg->conf->sem_stdout);
+ if (philo_finished(arg->conf))
+ return ;
sem_post(arg->forks);
+ if (philo_finished(arg->conf))
+ return ;
sem_post(arg->forks);
+ if (philo_finished(arg->conf))
+ return ;
usleep(arg->conf->timeout_sleep * 1000);
}
@@ -72,5 +86,7 @@ void event_die(t_philo *arg)
return ;
philo_put(arg->id, EVENT_DIE);
arg->conf->all_alive = false;
+ if (philo_finished(arg->conf))
+ return ;
sem_post(arg->conf->sem_stdout);
}