From: Lukas Jiriste Date: Fri, 22 Mar 2024 08:24:05 +0000 (+0100) Subject: Fix 2 bugs introduced by refactoring X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=cbc420d5e95de053be904b9dba4ff460d4158cd9;p=42%2Fphilosophers_old.git Fix 2 bugs introduced by refactoring The bugs where introduced in commit c091d1d. 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. --- 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)