diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2021-01-10 13:34:50 +0100 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2021-01-10 13:40:02 +0100 |
| commit | d552a2af95a3e03f937a94945369536d1eaae74a (patch) | |
| tree | dcbc6bb1af33219730086cfb5ca1ce0b83a17187 /philo_two/src/routine_meta.c | |
| parent | 5b03a0e341881ace66dc5cec5dcfba82fce8221d (diff) | |
| download | philosophers-d552a2af95a3e03f937a94945369536d1eaae74a.tar.gz philosophers-d552a2af95a3e03f937a94945369536d1eaae74a.tar.bz2 philosophers-d552a2af95a3e03f937a94945369536d1eaae74a.zip | |
Updated philo_two with better setup, Norming philo_two
Diffstat (limited to 'philo_two/src/routine_meta.c')
| -rw-r--r-- | philo_two/src/routine_meta.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/philo_two/src/routine_meta.c b/philo_two/src/routine_meta.c new file mode 100644 index 0000000..8bbc67a --- /dev/null +++ b/philo_two/src/routine_meta.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* routine_meta.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/01/10 13:31:54 by cacharle #+# #+# */ +/* Updated: 2021/01/10 13:32:38 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "philo_two.h" + +void *routine_flush(t_philo_conf *conf) +{ + while (true) + { + sem_wait(conf->sem_stdout); + philo_put_flush(); + sem_post(conf->sem_stdout); + usleep(250000); + } +} + +void *routine_meal_num(t_philo_conf *conf) +{ + long int i; + + if (conf->meal_num == -1) + return (NULL); + i = -1; + while (++i < conf->philo_num) + sem_wait(conf->sem_meal_num); + i = -1; + while (++i < conf->philo_num) + sem_wait(conf->sem_meal_num); + sem_wait(conf->sem_stdout); + sem_post(conf->sem_finish); + return (NULL); +} |
