fix: add verif for sleeping and not only for eating
This commit is contained in:
parent
19c5a53ba9
commit
caa4491fbb
12
main.c
12
main.c
@ -3,6 +3,7 @@
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "./philos.h"
|
||||
#include "./data.h"
|
||||
#include "./parsing.h"
|
||||
@ -70,8 +71,19 @@ void *check_routine(t_data *data)
|
||||
stop(data);
|
||||
return (NULL);
|
||||
}
|
||||
pthread_mutex_lock(&philo->last_sleep_mutex);
|
||||
// printf("time=%zu, last_sleep=%zu, life_expectency=%zu\n", get_time(), philo->last_sleep, data->life_expectency);
|
||||
ok = !(philo->last_sleep + data->life_expectency > get_time());
|
||||
pthread_mutex_unlock(&philo->last_sleep_mutex);
|
||||
if (ok == 1)
|
||||
{
|
||||
print_died(philo);
|
||||
stop(data);
|
||||
return (NULL);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
usleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user