aboutsummaryrefslogtreecommitdiff
path: root/philo_two/src/event.c
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2021-01-01 16:39:36 +0100
committerCharles Cabergs <me@cacharle.xyz>2021-01-01 16:39:36 +0100
commita73b1e33ae3a4f55e3dd19defa1b853bc58f1eeb (patch)
treeee14275a0f1ad9b8ddfa8feee1ee77ce0de5f285 /philo_two/src/event.c
parentb9d93edf40f228fcc6e18e9e6d0a1c5db498c004 (diff)
downloadphilosophers-a73b1e33ae3a4f55e3dd19defa1b853bc58f1eeb.tar.gz
philosophers-a73b1e33ae3a4f55e3dd19defa1b853bc58f1eeb.tar.bz2
philosophers-a73b1e33ae3a4f55e3dd19defa1b853bc58f1eeb.zip
Fixing meal num for philo_three
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);
}