diff options
Diffstat (limited to 'philo_one/src/main.c')
| -rw-r--r-- | philo_one/src/main.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/philo_one/src/main.c b/philo_one/src/main.c index eec5d4e..a9a6a63 100644 --- a/philo_one/src/main.c +++ b/philo_one/src/main.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/11/24 05:53:02 by cacharle #+# #+# */ -/* Updated: 2020/10/05 15:42:09 by cacharle ### ########.fr */ +/* Updated: 2020/12/30 14:04:42 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,7 +30,15 @@ static int st_setup( free(*philos); return (1); } + if (pthread_mutex_init(&conf->mutex_meal_num_finished_counter, NULL) != 0) + { + forks_destroy(*forks, conf->philo_num); + free(*philos); + pthread_mutex_destroy(&conf->mutex_stdout); + return (1); + } conf->all_alive = true; + conf->meal_num_finished_counter = 0; return (0); } @@ -42,7 +50,7 @@ int main(int argc, char **argv) if (!parse_args((t_philo_args*)&conf, argc, argv)) return (1); - if (conf.philo_num == 0) + if (conf.philo_num == 0 || conf.meal_num == 0) return (0); if (st_setup(&conf, &philos, &forks) != 0) return (1); @@ -52,11 +60,14 @@ int main(int argc, char **argv) free(philos); return (1); } - while (conf.all_alive) + while (conf.all_alive && (conf.meal_num != -1 && conf.meal_num_finished_counter != conf.philo_num)) + /* printf("%ld\n", conf.meal_num_finished_counter); */ ; + conf.all_alive = false; philos_detach(philos, conf.philo_num); forks_destroy(forks, conf.philo_num); pthread_mutex_destroy(&conf.mutex_stdout); + pthread_mutex_destroy(&conf.mutex_meal_num_finished_counter); free(philos); return (0); } |
