「🔨」 fix: print after death
This commit is contained in:
16
philo/log.c
16
philo/log.c
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/07 16:12:20 by adjoly #+# #+# */
|
||||
/* Updated: 2024/08/13 10:22:30 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/08/13 12:21:07 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -37,20 +37,24 @@ void log_philo(t_philo *philo)
|
||||
{
|
||||
uint32_t timestamp;
|
||||
struct timeval t1;
|
||||
static bool dead = false;
|
||||
static pthread_mutex_t print = {0};
|
||||
|
||||
gettimeofday(&t1, NULL);
|
||||
pthread_mutex_lock(&print);
|
||||
timestamp = get_time_in_ms(philo->t0, t1);
|
||||
if (philo->state == EAT)
|
||||
if (philo->state == EAT && dead == false)
|
||||
printf("%u %hu %s", timestamp, philo->id, EATING_MSG);
|
||||
else if (philo->state == THINK)
|
||||
else if (philo->state == THINK && dead == false)
|
||||
printf("%u %hu %s", timestamp, philo->id, THINK_MSG);
|
||||
else if (philo->state == SLEEP)
|
||||
else if (philo->state == SLEEP && dead == false)
|
||||
printf("%u %hu %s", timestamp, philo->id, SLEEP_MSG);
|
||||
else if (philo->state == DEAD)
|
||||
else if (philo->state == DEAD && dead == false)
|
||||
{
|
||||
dead = true;
|
||||
printf("%u %hu %s", timestamp, philo->id, DIED_MSG);
|
||||
else if (philo->state == FORK_TAKEN)
|
||||
}
|
||||
else if (philo->state == FORK_TAKEN && dead == false)
|
||||
printf("%u %hu %s", timestamp, philo->id, FORK_MSG);
|
||||
pthread_mutex_unlock(&print);
|
||||
}
|
||||
|
Reference in New Issue
Block a user