meilleur organisation code structures et variables
This commit is contained in:
10
srcs/exec.c
10
srcs/exec.c
@@ -19,14 +19,15 @@ int ret_unlock(t_mtx *mutex_1, t_mtx *mutex_2, int ret)
|
||||
int take_forks(t_philo *philo)
|
||||
{
|
||||
pthread_mutex_lock(&(philo->m_fork));
|
||||
if (philo->params->dead != 0)
|
||||
if (philo->global->dead != 0)
|
||||
return (ret_unlock(&(philo->m_fork), NULL, 1));
|
||||
print_message(philo, "has taken a fork");
|
||||
pthread_mutex_lock(&(philo->next->m_fork));
|
||||
if (philo->params->dead != 0)
|
||||
if (philo->global->dead != 0)
|
||||
return (ret_unlock(&(philo->m_fork), &(philo->next->m_fork), 1));
|
||||
print_message(philo, "has taken a fork");
|
||||
|
||||
update_time(philo);
|
||||
print_message(philo, "is eating");
|
||||
go_sleep(philo, philo->params->t_eat);
|
||||
|
||||
@@ -35,11 +36,6 @@ int take_forks(t_philo *philo)
|
||||
return (0);
|
||||
}
|
||||
|
||||
// int n_phi; // number_of_philosophers
|
||||
// int t_die; // time_to_die
|
||||
// int t_eat; // time_to_eat
|
||||
// int t_slp; // time_to_sleep
|
||||
// int n_eat; // [number_of_times_each_philosopher_must_eat]
|
||||
void *philo_exec(void *arg)
|
||||
{
|
||||
t_philo *philo;
|
||||
|
||||
Reference in New Issue
Block a user