From 1f3e187f6d79603c15ca9037048922e3ad2b9e50 Mon Sep 17 00:00:00 2001 From: Lukas Jiriste Date: Fri, 22 Mar 2024 09:24:05 +0100 Subject: [PATCH] Fix 2 bugs introduced by refactoring The bugs where introduced in commit f41587f. One bug was that not setting the optional argument number_of_times_each_philosopher_must_eat behaved the same as setting it to 0. The other bug was caused by not initializing a value. This caused the non-philosopher thread to sleep for much too long. --- philo/check_death.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/philo/check_death.c b/philo/check_death.c index 35b92eb..9cca50a 100644 --- a/philo/check_death.c +++ b/philo/check_death.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/19 15:53:52 by ljiriste #+# #+# */ -/* Updated: 2024/03/21 10:49:08 by ljiriste ### ########.fr */ +/* Updated: 2024/03/22 09:22:19 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,6 +45,8 @@ static int all_full(t_philo *philos, t_settings *set) size_t i; i = 0; + if (set->min_eats_num == 0) + return (0); while (i < set->philo_count) { if (philos[i].times_eaten < set->min_eats_num) @@ -59,7 +61,8 @@ static suseconds_t time_to_starve(t_philo *philos, t_settings *set) suseconds_t furthest_eaten; size_t i; - i = 0; + furthest_eaten = philos[0].last_eaten; + i = 1; while (i < set->philo_count) { if (furthest_eaten > philos[i].last_eaten) -- 2.30.2