reorganisation structs et timestamp global
This commit is contained in:
15
srcs/exec.c
15
srcs/exec.c
@@ -7,21 +7,24 @@ void go_sleep(t_philo *philo, int time)
|
||||
usleep(time * 1000);
|
||||
}
|
||||
|
||||
int ret_unlock(t_mtx mutex, int ret)
|
||||
int ret_unlock(t_mtx *mutex_1, t_mtx *mutex_2, int ret)
|
||||
{
|
||||
pthread_mutex_unlock(&mutex);
|
||||
if (mutex_1)
|
||||
pthread_mutex_unlock(mutex_1);
|
||||
if (mutex_2)
|
||||
pthread_mutex_unlock(mutex_2);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int take_forks(t_philo *philo)
|
||||
{
|
||||
pthread_mutex_lock(&(philo->m_fork));
|
||||
if (philo->death)
|
||||
return (ret_unlock(philo->m_fork, 1));
|
||||
if (philo->params->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->death)
|
||||
return (ret_unlock(philo->next->m_fork, 1));
|
||||
if (philo->params->dead != 0)
|
||||
return (ret_unlock(&(philo->m_fork), &(philo->next->m_fork), 1));
|
||||
print_message(philo, "has taken a fork");
|
||||
|
||||
print_message(philo, "is eating");
|
||||
|
||||
Reference in New Issue
Block a user