/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 12:49:40 by ljiriste #+# #+# */
-/* Updated: 2024/03/07 17:51:19 by ljiriste ### ########.fr */
+/* Updated: 2024/03/19 11:20:03 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
int res;
if (argc != 5 && argc != 6)
- return (0);
+ return (1);
res = 0;
res = res || parse_args(argv[1], &set->philo_count);
res = res || parse_arg(argv[2], &set->time_to_die);
}
+// "pthread_detach(threads[count]);" should be sufficient
+// instead of pthread_join(thread[count], NULL) but valgrind
+// then shows leaks
void cleanup(pthread_mutex_t *forks, t_philo *philos, pthread_t *threads, t_settings *set)
{
size_t count;
{
--count;
pthread_mutex_destroy(&forks[count]);
+ pthread_join(threads[count], NULL);
}
pthread_mutex_destroy(&set->terminal);
free(forks);
t_philo *philos;
if (init_settings(argc, argv, &settings))
+ {
+ printf("Invalid input arguments.\n");
return (1);
+ }
threads = malloc(sizeof(pthread_t) * settings.philo_count);
forks = init_forks(settings.philo_count);
philos = build_philos(forks, &settings);