Make a loop in check_death less busy
authorLukas Jiriste <ljiriste@student.42prague.com>
Tue, 19 Mar 2024 13:41:48 +0000 (14:41 +0100)
committerLukas Jiriste <ljiriste@student.42prague.com>
Fri, 22 Mar 2024 10:01:34 +0000 (11:01 +0100)
This change makes the main thread sleep for the time it would
take the "most hungry" philosopher to die. It is thus guaranteed
that no philosopher may die during the sleep.

philo/main.c

index 51415887c2ad2919cb334436ec5362716f835c26..35519388e22e5f51523a8d585b4429b64ad1b6e8 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/03/05 12:49:40 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/03/19 14:26:42 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/03/19 14:39:29 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -326,7 +326,7 @@ void        check_death(t_philo *philos, t_settings *set)
                        return ;
                }
                now = cur_time_sus();
-               //usleep(now - oldest);
+               usleep(set->time_to_die - (now - oldest));
        }
 }