fonctionne ok sauf pour 1

This commit is contained in:
Hugo LAMY
2022-01-26 13:52:30 +01:00
parent 6561340fb9
commit 2f747d0563
4 changed files with 20 additions and 13 deletions

View File

@@ -25,14 +25,14 @@ int ret_err_unlock(t_philo *philo, int nbr_fork)
int eat(t_philo *philo)
{
pthread_mutex_lock(&(philo->m_fork));
if (print_message(philo, WHITE, "has taken a fork", philo->global->dead))
if (print_message(philo, WHITE, "has taken a fork"))
return (ret_err_unlock(philo, 1));
pthread_mutex_lock(&(philo->next->m_fork));
if (print_message(philo, WHITE, "has taken a fork", philo->global->dead))
if (print_message(philo, WHITE, "has taken a fork"))
return (ret_err_unlock(philo, 2));
update_time(philo);
if (print_message(philo, B_YELLOW, "is eating", philo->global->dead))
if (print_message(philo, B_YELLOW, "is eating"))
return (ret_err_unlock(philo, 2));
philo->eat++;
if (philo->eat == philo->params->n_eat)
@@ -51,15 +51,15 @@ void *philo_exec(void *arg)
philo = (t_philo*)arg;
init_time(philo);
if (philo->p_nbr % 2 == 0)
usleep(10);
usleep(10 * 1000);
while (1)
{
if (eat(philo) != 0)
break ;
if (print_message(philo, B_BLUE, "is sleeping", philo->global->dead))
if (print_message(philo, B_BLUE, "is sleeping"))
break ;
go_sleep(philo, philo->params->t_slp);
if (print_message(philo, B_GREEN, "is thinking", philo->global->dead))
if (print_message(philo, B_GREEN, "is thinking"))
break ;
}
return (NULL);