Make the sleep between death check be max 100 us
authorLukas Jiriste <ljiriste@student.42prague.com>
Thu, 5 Sep 2024 09:43:59 +0000 (11:43 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Thu, 5 Sep 2024 09:43:59 +0000 (11:43 +0200)
This is implemented so that main checks well fed condition more
frequently. Without the well fed condition can be satisfied for a long
time before main notices, particularly for long time_to_death.

philo/main.c

index 2e7558326e00481d0403aaa95708e864642298ec..c736ff6a0291bbe6dde8b75442b510c25df20b0e 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/03/22 11:19:48 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/09/05 11:32:29 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/09/05 11:43:30 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -108,7 +108,8 @@ static enum e_end   watch_philosophers(t_diner *diner)
                        mutex_unlock(&diner->setting.end_lock);
                        return (well_fed);
                }
-               usleep(closest_death_time - usecs_since_start(diner->setting.start));
+               if (closest_death_time - usecs_since_start(diner->setting.start) > 100)
+                       usleep(100);
        }
 }