aboutsummaryrefslogtreecommitdiff
path: root/philo_one/src/main.c
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-12-30 14:06:17 +0100
committerCharles Cabergs <me@cacharle.xyz>2020-12-30 14:06:17 +0100
commitcf2ef2c3901f3da524079a9ad912dfb99e115a7e (patch)
tree7868f1f02a3fab1aa74606c1f9a3a00c0287976f /philo_one/src/main.c
parent2baa67fd7ad31fe53ab21d257a104478e787fb62 (diff)
downloadphilosophers-cf2ef2c3901f3da524079a9ad912dfb99e115a7e.tar.gz
philosophers-cf2ef2c3901f3da524079a9ad912dfb99e115a7e.tar.bz2
philosophers-cf2ef2c3901f3da524079a9ad912dfb99e115a7e.zip
Fixed meal_num args for philo_one
Diffstat (limited to 'philo_one/src/main.c')
-rw-r--r--philo_one/src/main.c17
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);
}