fix: update last_eat time after eat
This commit is contained in:
parent
f88abe9631
commit
e4b5e6ea0d
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/04/27 11:44:14 by cchauvet #+# #+# */
|
/* Created: 2023/04/27 11:44:14 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/05/25 17:30:05 by cchauvet ### ########.fr */
|
/* Updated: 2023/05/25 19:22:55 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -64,9 +64,6 @@ bool philo_eat(t_philo *philo, t_data *data)
|
|||||||
{
|
{
|
||||||
if (philo_take_forks(philo, data))
|
if (philo_take_forks(philo, data))
|
||||||
return (1);
|
return (1);
|
||||||
pthread_mutex_lock(&philo->last_eat_mutex);
|
|
||||||
philo->last_eat = get_time();
|
|
||||||
pthread_mutex_unlock(&philo->last_eat_mutex);
|
|
||||||
print_eating(philo);
|
print_eating(philo);
|
||||||
usleep(get_time_eat(philo, data) * 1000);
|
usleep(get_time_eat(philo, data) * 1000);
|
||||||
pthread_mutex_unlock(&data->forks[philo->id]);
|
pthread_mutex_unlock(&data->forks[philo->id]);
|
||||||
@ -76,6 +73,9 @@ bool philo_eat(t_philo *philo, t_data *data)
|
|||||||
pthread_mutex_lock(&philo->nb_meal_mutex);
|
pthread_mutex_lock(&philo->nb_meal_mutex);
|
||||||
philo->nb_meal++;
|
philo->nb_meal++;
|
||||||
pthread_mutex_unlock(&philo->nb_meal_mutex);
|
pthread_mutex_unlock(&philo->nb_meal_mutex);
|
||||||
|
pthread_mutex_lock(&philo->last_eat_mutex);
|
||||||
|
philo->last_eat = get_time();
|
||||||
|
pthread_mutex_unlock(&philo->last_eat_mutex);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user