From c33bbb4f66dbaca2f02b6f32c2d6bdb84be5f115 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Tue, 28 Jan 2025 13:56:07 +0100 Subject: Protect simulation_running with mutex --- philo/src/philo_eat.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'philo/src/philo_eat.c') diff --git a/philo/src/philo_eat.c b/philo/src/philo_eat.c index 3a0208e..b689f1f 100644 --- a/philo/src/philo_eat.c +++ b/philo/src/philo_eat.c @@ -6,7 +6,7 @@ /* By: dkaiser owner == 0) { fork->owner = philo->id; - ft_log(philo->id, "has taken a fork"); + ft_log(philo, "has taken a fork"); } pthread_mutex_unlock(&fork->mutex); } @@ -35,10 +35,10 @@ static void eat(t_philo *philo, t_fork *left_fork, t_fork *right_fork) int started_eating; started_eating = ft_cur_time_in_ms(); - ft_log(philo->id, "is eating"); + ft_log(philo, "is eating"); while (ft_cur_time_in_ms() < started_eating + philo->data->time_to_eat) { - if (!philo->data->simulation_running) + if (!is_simulation_running(philo->data)) return ; if (philo_die(philo)) return ; @@ -65,7 +65,7 @@ void philo_eat(t_philo *philo) usleep(250); take_fork(philo, left_fork); take_fork(philo, right_fork); - if (!philo->data->simulation_running) + if (!is_simulation_running(philo->data)) return ; if (philo_die(philo)) return ; -- cgit v1.2.3