aboutsummaryrefslogtreecommitdiff
path: root/philo_one/main.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-02-14 21:24:22 +0100
committerCharles <sircharlesaze@gmail.com>2020-02-14 21:24:22 +0100
commitf6a960c09c9593af72ff6da2c3ed501e01a0f429 (patch)
tree783c452486c2528fe0df25d76f49d1d4f20c1d47 /philo_one/main.c
parentadbe9cdb61e5d12299b8872b2ac27a48036bc95d (diff)
downloadphilosophers-f6a960c09c9593af72ff6da2c3ed501e01a0f429.tar.gz
philosophers-f6a960c09c9593af72ff6da2c3ed501e01a0f429.tar.bz2
philosophers-f6a960c09c9593af72ff6da2c3ed501e01a0f429.zip
philo one working (with what may be a hack)
Diffstat (limited to 'philo_one/main.c')
-rw-r--r--philo_one/main.c26
1 files changed, 8 insertions, 18 deletions
diff --git a/philo_one/main.c b/philo_one/main.c
index 94ac0f7..ddc9e52 100644
--- a/philo_one/main.c
+++ b/philo_one/main.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/24 05:53:02 by cacharle #+# #+# */
-/* Updated: 2020/02/14 01:41:21 by cacharle ### ########.fr */
+/* Updated: 2020/02/14 20:52:02 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,35 +19,25 @@ int main(int argc, char **argv)
t_philo *philos;
t_fork *forks;
t_routine_arg *routine_args;
- /* mutex_t mutex_stdout; */
- /* pthread_mutex_init(mutex_stdout); */
if (!parse_args(&philo_args, argc, argv))
return (1);
if ((forks = forks_new(philo_args.philo_num)) == 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(philos);
- free(forks);
return (1);
- }
+ philo_args.all_alive = TRUE;
+ pthread_mutex_init(&philo_args.mutex_all_alive, NULL);
+ pthread_mutex_init(&philo_args.mutex_stdout, NULL);
if (!philos_start(philos, routine_args, philo_args.philo_num))
- {
- free(philos);
- free(forks);
- free(routine_args);
return (1);
- }
- while (TRUE)
- if (philos_starved(philos, philo_args.philo_num))
- break;
+ while (philo_args.all_alive)
+ ;
philos_join(philos, philo_args.philo_num);
+ pthread_mutex_destroy(&philo_args.mutex_stdout);
+ pthread_mutex_destroy(&philo_args.mutex_all_alive);
free(routine_args);
free(philos);
forks_destroy(forks, philo_args.philo_num);