From e2caf487ab88a3ff11074ee6c75853edb908fef7 Mon Sep 17 00:00:00 2001 From: biralavor Date: Mon, 4 Nov 2024 15:09:34 -0300 Subject: [PATCH 1/2] adding boolean verification --- philo/headers/philo.h | 4 ++-- philo/src/12.dinner_routines.c | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/philo/headers/philo.h b/philo/headers/philo.h index 534ef7a..958af3e 100644 --- a/philo/headers/philo.h +++ b/philo/headers/philo.h @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/17 16:04:11 by umeneses #+# #+# */ -/* Updated: 2024/11/04 12:45:31 by umeneses ### ########.fr */ +/* Updated: 2024/11/04 15:00:21 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -159,7 +159,7 @@ void philos_in_async_mode(t_philo *philo); /* dinner routines functions */ void let_philo_eat_routine(t_philo *philo); -void let_philo_think_routine(t_philo *philo); +void let_philo_think_routine(t_philo *philo, bool before_spinlock); void let_philo_sleep_routine(t_philo *philo); bool is_philo_dead_manager(t_philo *philo); void *lonely_philo_routine(void *data); diff --git a/philo/src/12.dinner_routines.c b/philo/src/12.dinner_routines.c index 6fed1f5..939de72 100644 --- a/philo/src/12.dinner_routines.c +++ b/philo/src/12.dinner_routines.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/30 16:19:23 by umeneses #+# #+# */ -/* Updated: 2024/11/04 12:45:31 by umeneses ### ########.fr */ +/* Updated: 2024/11/04 15:02:28 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -71,12 +71,13 @@ void let_philo_eat_routine(t_philo *philo) safe_mutex_handler(&philo->second_chops->chops_mtx, UNLOCK); } -void let_philo_think_routine(t_philo *philo) +void let_philo_think_routine(t_philo *philo, bool before_spinlock) { long think_time; think_time = 0; - printer_with_mutex(THINKING, philo, DEBUG_MODE); + if (!before_spinlock) + printer_with_mutex(THINKING, philo, DEBUG_MODE); if (philo->table->set.total_philos % 2 == 0) return ; else From 8a05d53aad53b78a5d2fa9f67854c03600364a6a Mon Sep 17 00:00:00 2001 From: biralavor Date: Mon, 4 Nov 2024 15:10:24 -0300 Subject: [PATCH 2/2] controling thinking message to start only after eating --- philo/src/08.dinner_manager.c | 4 ++-- philo/src/10.synchronizers.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/philo/src/08.dinner_manager.c b/philo/src/08.dinner_manager.c index a063ec2..606aafc 100644 --- a/philo/src/08.dinner_manager.c +++ b/philo/src/08.dinner_manager.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/29 10:01:45 by umeneses #+# #+# */ -/* Updated: 2024/11/03 17:46:51 by umeneses ### ########.fr */ +/* Updated: 2024/11/04 15:09:04 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -61,7 +61,7 @@ void *dinner_runner(void *data) break ; let_philo_eat_routine(philo); let_philo_sleep_routine(philo); - let_philo_think_routine(philo); + let_philo_think_routine(philo, false); } return (NULL); } diff --git a/philo/src/10.synchronizers.c b/philo/src/10.synchronizers.c index 2b56e01..af8773f 100644 --- a/philo/src/10.synchronizers.c +++ b/philo/src/10.synchronizers.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/29 15:42:40 by umeneses #+# #+# */ -/* Updated: 2024/11/03 17:46:14 by umeneses ### ########.fr */ +/* Updated: 2024/11/04 14:59:17 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -48,6 +48,6 @@ void philos_in_async_mode(t_philo *philo) else { if (philo->id % 2 == 1) - let_philo_think_routine(philo); + let_philo_think_routine(philo, true); } }