/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/24 08:49:46 by ljiriste #+# #+# */
-/* Updated: 2024/05/30 11:39:51 by ljiriste ### ########.fr */
+/* Updated: 2024/05/30 14:25:33 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
philo = philo_void;
sem_wait(philo->philo_sem);
time = time_till_death(philo);
- while (time > 0)
+ while (time > 0 && philo->alive)
{
- if (!philo->alive)
- {
- sem_post(philo->philo_sem);
- return (NULL);
- }
sem_post(philo->philo_sem);
usleep(time / 2);
sem_wait(philo->philo_sem);
time = time_till_death(philo);
}
sem_wait(philo->semaphores.term);
- print_timestamp(philo, "died");
- philo->alive = 0;
- sem_post(philo->semaphores.death);
+ if (philo->alive)
+ {
+ print_timestamp(philo, "died");
+ philo->alive = 0;
+ sem_post(philo->semaphores.death);
+ sem_post(philo->semaphores.end);
+ }
+ else
+ sem_post(philo->semaphores.term);
sem_post(philo->philo_sem);
return (NULL);
}