From 3c3a4fc90cc617cde7bdf8a097c37d5e847637fb Mon Sep 17 00:00:00 2001 From: biralavor Date: Tue, 5 Nov 2024 11:02:41 -0300 Subject: [PATCH 1/2] fixing zombie mode --- philo/src/11.printer_with_mutex.c | 8 ++++---- philo/src/13.monitor.c | 13 +++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/philo/src/11.printer_with_mutex.c b/philo/src/11.printer_with_mutex.c index 28dfe49..131c40e 100644 --- a/philo/src/11.printer_with_mutex.c +++ b/philo/src/11.printer_with_mutex.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/30 11:12:00 by umeneses #+# #+# */ -/* Updated: 2024/11/04 19:00:53 by umeneses ### ########.fr */ +/* Updated: 2024/11/05 11:00:04 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,11 +20,11 @@ void printer_manager(t_philo_status status, t_philo *philo, int debug) if (philo->full) return ; safe_mutex_handler(&philo->table->printer_mtx, LOCK); - if (debug == 1) + if (debug == 1 && !this_is_the_end_of_dinner(philo->table)) printer_with_mutex_chopsticks(status, philo, elapsed); - else if (debug == 2) + else if (debug == 2 && !this_is_the_end_of_dinner(philo->table)) printer_with_mutex_debug(status, philo, elapsed); - else + else if (!this_is_the_end_of_dinner(philo->table)) printer_with_mutex_classic(status, philo, elapsed); safe_mutex_handler(&philo->table->printer_mtx, UNLOCK); } diff --git a/philo/src/13.monitor.c b/philo/src/13.monitor.c index 841c314..9eb9b66 100644 --- a/philo/src/13.monitor.c +++ b/philo/src/13.monitor.c @@ -6,7 +6,7 @@ /* By: umeneses +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/04 18:57:56 by umeneses #+# #+# */ -/* Updated: 2024/11/04 18:58:26 by umeneses ### ########.fr */ +/* Updated: 2024/11/05 10:59:03 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,8 +30,8 @@ void *monitor_runner(void *data) { if (is_philo_dead_manager(table->philos + idx)) { - set_bool(&table->table_mtx, &table->this_is_the_end, true); printer_manager(DEAD, table->philos + idx, DEBUG_MODE); + set_bool(&table->table_mtx, &table->this_is_the_end, true); } } } @@ -41,14 +41,15 @@ void *monitor_runner(void *data) bool is_philo_dead_manager(t_philo *philo) { long time_to_die; - long elapsed; + long current; + long last_meal; if (get_bool(&philo->philo_mtx, &philo->full)) return (false); - elapsed = ft_gettime(MILLISECOND) - get_long(&philo->philo_mtx, - &philo->time_of_last_meal); + current = ft_gettime(MILLISECOND); + last_meal = get_long(&philo->philo_mtx, &philo->time_of_last_meal); time_to_die = philo->table->set.time_to_die / 1e3; - if (elapsed > time_to_die) + if (current - last_meal > time_to_die) return (true); return (false); } From f5ca5d2a852901ba1134dc473d9d4a2e2880169d Mon Sep 17 00:00:00 2001 From: biralavor Date: Tue, 5 Nov 2024 11:13:05 -0300 Subject: [PATCH 2/2] fxiing norminette --- philo/src/12.dinner_routines.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/philo/src/12.dinner_routines.c b/philo/src/12.dinner_routines.c index bb57c78..0ad5336 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/05 10:49:33 by umeneses ### ########.fr */ +/* Updated: 2024/11/05 11:12:50 by umeneses ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,8 +41,8 @@ void let_philo_think_routine(t_philo *philo, bool before_spinlock) return ; else { - think_time = (philo->table->set.time_to_eat - * 2) - philo->table->set.time_to_sleep; + think_time = (philo->table->set.time_to_eat * 2) + - philo->table->set.time_to_sleep; if (think_time < 0) think_time = 0; precise_usleep(think_time * 0.5, philo->table);