aboutsummaryrefslogtreecommitdiff
path: root/philo_two/src/routine.c
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2021-01-04 12:20:25 +0100
committerCharles Cabergs <me@cacharle.xyz>2021-01-04 12:20:25 +0100
commit907debbb7d1e7ccc4914805cfe4acbed92b82bcc (patch)
tree199d60e60d9d9b689062c5f08d6381c090127619 /philo_two/src/routine.c
parent7e971b3fa805c40d02ac3e996ab1d181f9584866 (diff)
downloadphilosophers-907debbb7d1e7ccc4914805cfe4acbed92b82bcc.tar.gz
philosophers-907debbb7d1e7ccc4914805cfe4acbed92b82bcc.tar.bz2
philosophers-907debbb7d1e7ccc4914805cfe4acbed92b82bcc.zip
Added buffered output, Added waiting for all to be started
Diffstat (limited to 'philo_two/src/routine.c')
-rw-r--r--philo_two/src/routine.c11
1 files changed, 6 insertions, 5 deletions
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 <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);