diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2021-01-08 22:11:19 +0100 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2021-01-08 22:11:19 +0100 |
| commit | a69a877b3a2758aafe3de0db87a56063b28ed00f (patch) | |
| tree | 2f0e61aa28cea420fd808fb51eee46ba004d9698 /philo_two/src/routine.c | |
| parent | 36c5e3a81de8b910bc04a37994b53296c1540353 (diff) | |
| download | philosophers-a69a877b3a2758aafe3de0db87a56063b28ed00f.tar.gz philosophers-a69a877b3a2758aafe3de0db87a56063b28ed00f.tar.bz2 philosophers-a69a877b3a2758aafe3de0db87a56063b28ed00f.zip | |
Add sem_grab in philo_two and philo_three to fix philosophers each taking 1 fork
Diffstat (limited to 'philo_two/src/routine.c')
| -rw-r--r-- | philo_two/src/routine.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/philo_two/src/routine.c b/philo_two/src/routine.c index d69488d..52bf53d 100644 --- a/philo_two/src/routine.c +++ b/philo_two/src/routine.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 23:00:07 by cacharle #+# #+# */ -/* Updated: 2021/01/08 16:31:27 by charles ### ########.fr */ +/* Updated: 2021/01/08 20:18:00 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,18 +19,15 @@ void *routine_philo(t_philo *arg) eat_counter = 0; sem_wait(arg->conf->sem_start); - /* if (arg->conf->philo_num % 2 == 0 && arg->id % 2 == 0) */ - /* usleep(1000); */ - /* if (arg->conf->philo_num % 2 == 1 && arg->id % 3 == 0) */ - /* usleep(1000); */ - /* if (arg->conf->philo_num % 2 == 1 && arg->id % 3 == 1) */ - /* usleep(500); */ arg->time_last_eat = h_time_now(); if (pthread_create(&thread_death, NULL, (t_routine)routine_death, arg) != 0) return (NULL); while (true) { + sem_wait(arg->conf->sem_grab); event_take_fork(arg); + event_take_fork(arg); + sem_post(arg->conf->sem_grab); arg->time_last_eat = h_time_now(); event_eat(arg); if (arg->conf->meal_num != -1 && ++eat_counter == arg->conf->meal_num) |
