From 907debbb7d1e7ccc4914805cfe4acbed92b82bcc Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Mon, 4 Jan 2021 12:20:25 +0100 Subject: Added buffered output, Added waiting for all to be started --- philo_two/src/routine.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'philo_two/src/routine.c') diff --git a/philo_two/src/routine.c b/philo_two/src/routine.c index 3c04817..d6e1df3 100644 --- a/philo_two/src/routine.c +++ b/philo_two/src/routine.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 23:00:07 by cacharle #+# #+# */ -/* Updated: 2021/01/03 12:57:27 by cacharle ### ########.fr */ +/* Updated: 2021/01/04 12:17:48 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,17 +17,18 @@ void *routine_philo(t_philo *arg) long int eat_counter; pthread_t thread_death; + eat_counter = 0; + sem_wait(arg->conf->sem_start); + if (arg->id % 2 == 0) + usleep(500); arg->time_last_eat = h_time_now(); if (pthread_create(&thread_death, NULL, (t_routine)routine_death, arg) != 0) return (NULL); - eat_counter = 0; - event_think(arg); while (true) { event_take_fork(arg); - event_take_fork(arg); - event_eat(arg); arg->time_last_eat = h_time_now(); + event_eat(arg); if (arg->conf->meal_num != -1 && ++eat_counter == arg->conf->meal_num) { sem_wait(arg->conf->sem_stdout); -- cgit