From 1a7c6c5a0ed9a5aae1fe45c3af335c120c2dc642 Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 10 Feb 2020 00:34:47 +0100 Subject: WIP: philo one --- philo_one/main.c | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) (limited to 'philo_one/main.c') diff --git a/philo_one/main.c b/philo_one/main.c index 3bb1181..ef00a0b 100644 --- a/philo_one/main.c +++ b/philo_one/main.c @@ -6,21 +6,48 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/11/24 05:53:02 by cacharle #+# #+# */ -/* Updated: 2019/11/24 06:35:10 by cacharle ### ########.fr */ +/* Updated: 2020/02/10 01:29:50 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "philo_one.h" + int main(int argc, char **argv) { - if (argc != 5 || argc != 6) + t_philo_args philo_args; + t_philo *philos; + t_fork *forks; + t_routine_arg *routine_args; + + if (!parse_args(&philo_args, argc, argv)) + return (1); + if ((forks = forks_new(philo_args.philo_num - 1)) == NULL) + return (1); + if ((philos = philos_new(philo_args.philo_num)) == NULL) + { + free(forks); + return (1); + } + if ((routine_args = forks_dispatch(philos, forks, &philo_args)) == NULL) + { + free(forks); + free(philos); + return (1); + } + if (!philos_start(philos, routine_args, philo_args.philo_num)) + { + free(philos); + free(forks); + free(routine_args); return (1); - int philo_nb = ft_atoi(argv[1]); - int death_timer = ft_atoi(argv[2]); - int eat_timer = ft_atoi(argv[3]); - int sleep_timer = ft_atoi(argv[4]); - if (argc == 6) - int eat_nb = ft_atoi(argv[5]); + } + while (TRUE) + if (philos_starved(philos, philo_args.philo_num)) + break; + philos_join(philos, philo_args.philo_num); + free(philos); + free(forks); + free(routine_args); return (0); } -- cgit