ajout fonction sleep uqi compare action vs death
This commit is contained in:
16
srcs/exec.c
16
srcs/exec.c
@@ -3,8 +3,20 @@
|
||||
// TODO : compare time with time before dying
|
||||
void go_sleep(t_philo *philo, int time)
|
||||
{
|
||||
(void)philo;
|
||||
usleep(time * 1000);
|
||||
long int start_time;
|
||||
long int death_time;
|
||||
long int next_step_time;
|
||||
|
||||
start_time = philo->t_last_meal_u;
|
||||
if (start_time == 0)
|
||||
start_time = philo->global->t_start_u;
|
||||
|
||||
death_time = start_time + (philo->params->t_die * 1000);
|
||||
next_step_time = start_time + (time * 1000);
|
||||
if (death_time < next_step_time)
|
||||
usleep(philo->params->t_die * 1000);
|
||||
else
|
||||
usleep(time * 1000);
|
||||
}
|
||||
|
||||
int ret_unlock(t_mtx *mutex_1, t_mtx *mutex_2, int ret)
|
||||
|
||||
Reference in New Issue
Block a user