From cc066f987dec4898b470ab23e54012493ba14386 Mon Sep 17 00:00:00 2001 From: biralavor Date: Sun, 3 Nov 2024 15:09:06 -0300 Subject: [PATCH 1/3] fixing thinking routine if total philos is odd --- philo/src/12.dinner_routines.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/philo/src/12.dinner_routines.c b/philo/src/12.dinner_routines.c index 38534a8..76596e0 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/03 12:58:42 by umeneses ### ########.fr */ +/* Updated: 2024/11/03 15:08:41 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -75,11 +75,11 @@ void let_philo_think_routine(t_philo *philo) { long think_time; - think_time = philo->table->set.time_to_eat * 2 - philo->table->set.time_to_sleep; + if (philo->table->set.total_meals % 2 != 0) + think_time = philo->table->set.time_to_eat + * 2 - philo->table->set.time_to_sleep; printer_with_mutex(THINKING, philo, DEBUG_MODE); precise_usleep(think_time, philo->table); - // safe_mutex_handler(philo->philo_mtx, LOCK); - // safe_mutex_handler(philo->philo_mtx, UNLOCK); } void let_philo_sleep_routine(t_philo *philo) From aeac44a86b33fdc1af08ea1fce26ba1cbc9f7f84 Mon Sep 17 00:00:00 2001 From: biralavor Date: Sun, 3 Nov 2024 15:12:12 -0300 Subject: [PATCH 2/3] fixing uninitilized variable --- philo/src/12.dinner_routines.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/philo/src/12.dinner_routines.c b/philo/src/12.dinner_routines.c index 76596e0..8babf30 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/03 15:08:41 by umeneses ### ########.fr */ +/* Updated: 2024/11/03 15:11:52 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -75,6 +75,7 @@ void let_philo_think_routine(t_philo *philo) { long think_time; + think_time = 0; if (philo->table->set.total_meals % 2 != 0) think_time = philo->table->set.time_to_eat * 2 - philo->table->set.time_to_sleep; From 7d32940019f373c0e3a15d5d7c31428491056a2d Mon Sep 17 00:00:00 2001 From: biralavor Date: Sun, 3 Nov 2024 15:17:34 -0300 Subject: [PATCH 3/3] protecting think time of negative --- philo/src/12.dinner_routines.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/philo/src/12.dinner_routines.c b/philo/src/12.dinner_routines.c index 8babf30..6a10edf 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/03 15:11:52 by umeneses ### ########.fr */ +/* Updated: 2024/11/03 15:17:01 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -79,6 +79,8 @@ void let_philo_think_routine(t_philo *philo) if (philo->table->set.total_meals % 2 != 0) think_time = philo->table->set.time_to_eat * 2 - philo->table->set.time_to_sleep; + if (think_time < 0) + think_time = 0; printer_with_mutex(THINKING, philo, DEBUG_MODE); precise_usleep(think_time, philo->table); }