diff --git a/philo/sources/ft_actions.c b/philo/sources/ft_actions.c index a6b6243..4314795 100644 --- a/philo/sources/ft_actions.c +++ b/philo/sources/ft_actions.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/10 00:23:09 by rparodi #+# #+# */ -/* Updated: 2024/07/07 20:00:00 by rparodi ### ########.fr */ +/* Updated: 2024/07/18 18:42:02 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,10 @@ void ft_logs(t_str msg, t_philo *philo) { + pthread_mutex_lock(philo->dead_lock); + if (philo->dead_check == true) + return ((void) pthread_mutex_unlock(philo->dead_lock)); + pthread_mutex_unlock(philo->dead_lock); pthread_mutex_lock(philo->print_lock); const t_usize time = ft_time() - philo->start_time; if (msg != NULL) @@ -34,17 +38,17 @@ t_error ft_start_eating(t_philo *philo) { if (philo->id % 2 == 0) { - pthread_mutex_lock(philo->l_fork); - ft_logs("has taken a fork\n", philo); pthread_mutex_lock(philo->r_fork); ft_logs("has taken a fork\n", philo); + pthread_mutex_lock(philo->l_fork); + ft_logs("has taken a fork\n", philo); } else { - pthread_mutex_lock(philo->r_fork); - ft_logs("has taken a fork\n", philo); pthread_mutex_lock(philo->l_fork); ft_logs("has taken a fork\n", philo); + pthread_mutex_lock(philo->r_fork); + ft_logs("has taken a fork\n", philo); } return (ft_ending_eating(philo)); } diff --git a/philo/sources/parsing_args.c b/philo/sources/parsing_args.c index c602f08..5803a59 100644 --- a/philo/sources/parsing_args.c +++ b/philo/sources/parsing_args.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/04 11:42:37 by rparodi #+# #+# */ -/* Updated: 2024/07/11 17:31:53 by rparodi ### ########.fr */ +/* Updated: 2024/07/18 18:37:43 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,7 +23,7 @@ t_error ft_parsing_args(t_i32 argc, t_str *argv, t_philo *philo) philo->nb_eat = tmp; } else - philo->t_eat = ~0; + philo->nb_eat = -1; ft_atou(argv[1], &tmp); philo->nb_philo = tmp; ft_atou(argv[2], &tmp); diff --git a/philo/sources/routine.c b/philo/sources/routine.c index 8f875ce..2429d59 100644 --- a/philo/sources/routine.c +++ b/philo/sources/routine.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/11 11:42:31 by rparodi #+# #+# */ -/* Updated: 2024/07/11 18:10:49 by rparodi ### ########.fr */ +/* Updated: 2024/07/18 18:38:04 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -48,6 +48,8 @@ void counting_launch(t_philo *philo, t_u8 *counter) t_usize i; i = 0; + if (philo->nb_eat == -1) + return ; while (i < philo[0].nb_philo) { pthread_mutex_lock(philo[i].check_eating_count);