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_three/src/main.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_three/src/main.c')
| -rw-r--r-- | philo_three/src/main.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/philo_three/src/main.c b/philo_three/src/main.c index 0b3397c..8790140 100644 --- a/philo_three/src/main.c +++ b/philo_three/src/main.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/15 00:45:24 by cacharle #+# #+# */ -/* Updated: 2021/01/08 15:11:05 by charles ### ########.fr */ +/* Updated: 2021/01/08 20:23:28 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,6 +37,8 @@ static int st_destroy(t_sems *sems, pid_t *pids, int philo_num) sem_unlink(PHILO_SEM_FINISH_NAME); sem_close(sems->sem_start); sem_unlink(PHILO_SEM_START_NAME); + sem_close(sems->sem_grab); + sem_unlink(PHILO_SEM_GRAB_NAME); return (1); } @@ -58,6 +60,7 @@ static int st_setup( args->meal_num == -1 ? 1 : args->philo_num)) == SEM_FAILED || (sems->sem_start = st_sem_create(PHILO_SEM_START_NAME, args->philo_num)) == SEM_FAILED + || (sems->sem_grab = st_sem_create(PHILO_SEM_GRAB_NAME, 1)) == SEM_FAILED || (*pids = malloc(sizeof(pid_t) * args->philo_num)) == NULL) return (st_destroy(sems, *pids, 0)); i = -1; |
