possible race conflicts resolut
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/01/26 15:30:28 by hulamy #+# #+# */
|
||||
/* Updated: 2022/01/26 18:51:44 by hulamy ### ########.fr */
|
||||
/* Updated: 2022/01/30 15:43:19 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -18,7 +18,7 @@ static void action_delay(t_philo *philo, int action_time)
|
||||
int death_time;
|
||||
|
||||
gettimeofday(&stime, NULL);
|
||||
death_time = philo->params->t_die - diff_time(&philo->t_last_meal, &stime);
|
||||
death_time = philo->params->t_die - diff_time(philo, &stime);
|
||||
if (death_time > action_time)
|
||||
usleep(action_time * 1000);
|
||||
else if (death_time > 0)
|
||||
@@ -45,7 +45,9 @@ static int eat(t_philo *philo)
|
||||
if (print_message(philo, B_YELLOW, "is eating"))
|
||||
return (ret_err_unlock(philo, 2));
|
||||
action_delay(philo, philo->params->t_eat);
|
||||
pthread_mutex_lock(&(philo->m_eat));
|
||||
philo->eat_count++;
|
||||
pthread_mutex_unlock(&(philo->m_eat));
|
||||
pthread_mutex_unlock(&(philo->next->m_fork));
|
||||
pthread_mutex_unlock(&(philo->m_fork));
|
||||
return (0);
|
||||
|
||||
Reference in New Issue
Block a user