This is done so that a philosopher truly cannot write to terminal after
it dies. Before this commit, a philosopher that is alive would wait for
term semaphore. Meanwhile something could change his state to not alive
but he could then get the semaphore and print anyway.
I thought about having the condition inside as well as on the outside
of the sem_wait. But having it just after the sem_wait should be
alright.
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/09 09:13:40 by ljiriste #+# #+# */
-/* Updated: 2024/05/24 15:32:49 by ljiriste ### ########.fr */
+/* Updated: 2024/05/30 14:45:17 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
void report(t_philo *philo, const char *str)
{
+ sem_wait(philo->semaphores.term);
if (is_alive(philo))
- {
- sem_wait(philo->semaphores.term);
print_timestamp(philo, str);
- sem_post(philo->semaphores.term);
- }
+ sem_post(philo->semaphores.term);
return ;
}