diff options
| author | Dominik Kaiser | 2025-01-28 13:56:07 +0100 |
|---|---|---|
| committer | Dominik Kaiser | 2025-01-28 13:56:07 +0100 |
| commit | c33bbb4f66dbaca2f02b6f32c2d6bdb84be5f115 (patch) | |
| tree | a33a18e211b4fcae9e6d6dd8257ac56a5ae603f9 /philo/src/philo_eat.c | |
| parent | ec7a989cf45440e41d43e7fa2d2ce660fa499933 (diff) | |
| download | Philosophers-c33bbb4f66dbaca2f02b6f32c2d6bdb84be5f115.tar.gz Philosophers-c33bbb4f66dbaca2f02b6f32c2d6bdb84be5f115.zip | |
Protect simulation_running with mutex
Diffstat (limited to 'philo/src/philo_eat.c')
| -rw-r--r-- | philo/src/philo_eat.c | 10 |
1 files changed, 5 insertions, 5 deletions
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 <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/01/21 18:15:40 by dkaiser #+# #+# */ -/* Updated: 2025/01/28 13:05:31 by dkaiser ### ########.fr */ +/* Updated: 2025/01/28 13:42:19 by dkaiser ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,7 @@ static void take_fork(t_philo *philo, t_fork *fork) if (fork->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 ; |
