aboutsummaryrefslogtreecommitdiff
path: root/philo_two/src/routine.c
diff options
context:
space:
mode:
Diffstat (limited to 'philo_two/src/routine.c')
-rw-r--r--philo_two/src/routine.c11
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)