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:49 by hulamy #+# #+# */
|
||||
/* Updated: 2022/01/26 18:52:32 by hulamy ### ########.fr */
|
||||
/* Updated: 2022/01/30 15:50:27 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -19,10 +19,12 @@ static int is_finished(t_philo *philo, struct timeval *stime)
|
||||
|
||||
if (philo->global->satiated_count == philo->params->n_phi)
|
||||
{
|
||||
pthread_mutex_lock(&(philo->global->m_stop));
|
||||
philo->global->stop = 1;
|
||||
pthread_mutex_unlock(&(philo->global->m_stop));
|
||||
return (1);
|
||||
}
|
||||
time = diff_time(&philo->t_last_meal, stime);
|
||||
time = diff_time(philo, stime);
|
||||
if (time >= philo->params->t_die)
|
||||
{
|
||||
pthread_mutex_lock(&(philo->global->m_print));
|
||||
@@ -38,11 +40,14 @@ static int is_finished(t_philo *philo, struct timeval *stime)
|
||||
|
||||
int is_satiated(t_philo *philo)
|
||||
{
|
||||
pthread_mutex_lock(&(philo->m_eat));
|
||||
if (philo->eat_count == philo->params->n_eat)
|
||||
{
|
||||
philo->global->satiated_count++;
|
||||
pthread_mutex_unlock(&(philo->m_eat));
|
||||
return (1);
|
||||
}
|
||||
pthread_mutex_unlock(&(philo->m_eat));
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user