fix: stop when nb_meal is reached
This commit is contained in:
parent
891431c1be
commit
02a80af93b
2
data.h
2
data.h
@ -9,7 +9,7 @@ typedef struct s_data
|
||||
size_t sleep_time;
|
||||
size_t life_expectency;
|
||||
size_t nb_philos;
|
||||
ssize_t nb_meals;
|
||||
size_t nb_meals;
|
||||
void **philos;
|
||||
pthread_t *threads;
|
||||
pthread_mutex_t *forks;
|
||||
|
4
main.c
4
main.c
@ -65,12 +65,12 @@ void *check_routine(t_data *data)
|
||||
print_died(philo);
|
||||
return (NULL);
|
||||
}
|
||||
i++;
|
||||
if ((ssize_t) get_min_meal(data) == data->nb_meals)
|
||||
if (get_min_meal(data) >= data->nb_meals)
|
||||
{
|
||||
stop(data);
|
||||
return (NULL);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
3
philo.c
3
philo.c
@ -63,6 +63,9 @@ bool philo_eat(t_philo *philo, t_data *data)
|
||||
pthread_mutex_lock(&philo->last_eat_mutex);
|
||||
philo->last_eat = get_time();
|
||||
pthread_mutex_unlock(&philo->last_eat_mutex);
|
||||
pthread_mutex_lock(&philo->nb_meal_mutex);
|
||||
philo->nb_meal++;
|
||||
pthread_mutex_unlock(&philo->nb_meal_mutex);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
2
philo.h
2
philo.h
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/08 14:38:14 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/04/25 14:05:15 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/04/25 16:41:14 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user