From c601bdf3259ddcf6bdcaae0b911d4defdfd11bef Mon Sep 17 00:00:00 2001 From: adjoly <adamjly@proton.me> Date: Fri, 23 Aug 2024 16:31:14 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=94=A8=E3=80=8D=20fix:=20fixed?= =?UTF-8?q?=20datarace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- philo/eat.c | 4 +++- philo/philo_routine.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/philo/eat.c b/philo/eat.c index 1392c9b..c54f409 100644 --- a/philo/eat.c +++ b/philo/eat.c @@ -6,7 +6,7 @@ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/08 17:29:51 by adjoly #+# #+# */ -/* Updated: 2024/08/12 21:04:57 by adjoly ### ########.fr */ +/* Updated: 2024/08/23 15:35:29 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -42,7 +42,9 @@ bool philo_eat(t_philo *philo) return (true); pthread_mutex_unlock(&philo->fork.left); pthread_mutex_unlock(philo->fork.right); + pthread_mutex_lock(philo->check); if (philo->data.no_meal == false && philo->meal_left > 0) philo->meal_left--; + pthread_mutex_unlock(philo->check); return (false); } diff --git a/philo/philo_routine.c b/philo/philo_routine.c index fec7ee1..2023145 100644 --- a/philo/philo_routine.c +++ b/philo/philo_routine.c @@ -6,7 +6,7 @@ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/22 21:24:53 by adjoly #+# #+# */ -/* Updated: 2024/08/12 21:03:47 by adjoly ### ########.fr */ +/* Updated: 2024/08/23 15:31:42 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */