Compare commits
No commits in common. "caa4491fbbb3e38fdbbf7b525e64708953352e42" and "cb2e29d18b22ef284fb9f2a6e49691cc83355c5d" have entirely different histories.
caa4491fbb
...
cb2e29d18b
12
main.c
12
main.c
@ -3,7 +3,6 @@
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "./philos.h"
|
||||
#include "./data.h"
|
||||
#include "./parsing.h"
|
||||
@ -71,19 +70,8 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
25
philo.c
25
philo.c
@ -38,17 +38,7 @@ void eat(t_philo *philo, t_data *data)
|
||||
print_take_a_fork(philo);
|
||||
print_take_a_fork(philo);
|
||||
print_eating(philo);
|
||||
pthread_mutex_lock(&philo->last_eat_mutex);
|
||||
if (get_time() - philo->last_eat + data->eat_time > data->life_expectency)
|
||||
{
|
||||
pthread_mutex_unlock(&philo->last_eat_mutex);
|
||||
usleep((data->life_expectency -
|
||||
(get_time() - philo->last_eat)) * 1000);
|
||||
return ;
|
||||
}
|
||||
else
|
||||
usleep(data->eat_time * 1000);
|
||||
pthread_mutex_unlock(&philo->last_eat_mutex);
|
||||
pthread_mutex_lock(&philo->nb_meal_mutex);
|
||||
philo->nb_meal++;
|
||||
pthread_mutex_unlock(&philo->nb_meal_mutex);
|
||||
@ -91,22 +81,7 @@ bool philo_eat(t_philo *philo, t_data *data)
|
||||
void philo_sleep(t_data *data, t_philo *philo)
|
||||
{
|
||||
print_sleeping(philo);
|
||||
pthread_mutex_lock(&philo->last_sleep_mutex);
|
||||
// printf("time=%zu, last_sleep=%zu, sleep_time=%zu, life_expectency=%zu\n", get_time(), philo->last_sleep, data->sleep_time, data->life_expectency);
|
||||
if (get_time() - philo->last_sleep + data->sleep_time > data->life_expectency)
|
||||
{
|
||||
pthread_mutex_unlock(&philo->last_sleep_mutex);
|
||||
// printf("rompiche=%zu\n", (data->life_expectency -
|
||||
// (get_time() - philo->last_sleep)));
|
||||
usleep((data->life_expectency -
|
||||
(get_time() - philo->last_sleep)) * 1000);
|
||||
return ;
|
||||
}
|
||||
else
|
||||
usleep(data->sleep_time * 1000);
|
||||
philo->last_sleep = get_time();
|
||||
pthread_mutex_unlock(&philo->last_sleep_mutex);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user