aboutsummaryrefslogtreecommitdiff
path: root/philo_two/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'philo_two/src/main.c')
-rw-r--r--philo_two/src/main.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/philo_two/src/main.c b/philo_two/src/main.c
index 27dce34..c0c9fd6 100644
--- a/philo_two/src/main.c
+++ b/philo_two/src/main.c
@@ -6,39 +6,38 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/14 22:45:23 by cacharle #+# #+# */
-/* Updated: 2020/09/30 08:44:46 by cacharle ### ########.fr */
+/* Updated: 2020/09/30 09:58:01 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "philo_two.h"
-#define PHILO_SEM_NAME "philo_two"
+#define PHILO_SEM_NAME "semaphore_philo_two"
int main(int argc, char **argv)
{
int i;
t_philo_conf conf;
- t_routine_arg *routine_args;
+ t_philo *philos;
sem_t *forks;
pthread_t *threads;
if (!parse_args((t_philo_args*)&conf, argc, argv))
return (1);
sem_unlink(PHILO_SEM_NAME);
- forks = sem_open(PHILO_SEM_NAME, O_CREAT, 0700, conf.philo_num);
+ forks = sem_open(PHILO_SEM_NAME, O_CREAT | O_EXCL, 0600, conf.philo_num);
if (forks == SEM_FAILED)
return (1);
- if ((routine_args = routine_args_create(&conf, forks)) == NULL)
+ if ((philos = routine_create_philos(&conf, forks)) == NULL)
return (1);
if ((threads = malloc(sizeof(pthread_t) * conf.philo_num)) == NULL)
return (1);
conf.all_alive = true;
- pthread_mutex_init(&conf.mutex_all_alive, NULL);
pthread_mutex_init(&conf.mutex_stdout, NULL);
i = -1;
while (++i < conf.philo_num)
- if (pthread_create(threads + i, NULL, (t_routine)routine_philo, routine_args + i) < 0)
+ if (pthread_create(threads + i, NULL, (t_routine)routine_philo, philos + i) < 0)
return (1);
while (conf.all_alive)
;
@@ -50,8 +49,7 @@ int main(int argc, char **argv)
sem_unlink(PHILO_SEM_NAME);
pthread_mutex_destroy(&conf.mutex_stdout);
- pthread_mutex_destroy(&conf.mutex_all_alive);
free(threads);
- free(routine_args);
+ free(philos);
return (0);
}