From f8f509dd598f3050e58acbab0f3dfe3f38906694 Mon Sep 17 00:00:00 2001 From: hugogogo Date: Thu, 13 Jan 2022 09:56:09 +0100 Subject: [PATCH] init mutex broken --- headers/philo_proto.h | 2 -- srcs/init.c | 8 +++++--- srcs/main.c | 1 - 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/headers/philo_proto.h b/headers/philo_proto.h index 4a26d36..ca44930 100644 --- a/headers/philo_proto.h +++ b/headers/philo_proto.h @@ -1,8 +1,6 @@ #ifndef PHILO_PROTO_H # define PHILO_PROTO_H -// t_mtx mutex; - // init.c t_philo *init(int ac, char **av, pthread_t **id); diff --git a/srcs/init.c b/srcs/init.c index 7fe9698..5c6d5a0 100644 --- a/srcs/init.c +++ b/srcs/init.c @@ -62,7 +62,7 @@ t_philo *init(int ac, char **av, pthread_t **id) { t_philo *philo; t_params *params; - t_mtx msg_mtx; + t_mtx *m_print; params = init_params(ac, av); if (params == NULL) @@ -70,8 +70,10 @@ t_philo *init(int ac, char **av, pthread_t **id) *id = malloc(sizeof(int) * params->n_phi); if (*id == NULL) return (NULL); - pthread_mutex_init(&msg_mtx, NULL); - philo = init_chain_philo(params, &msg_mtx); + m_print = NULL; + if (pthread_mutex_init(m_print, NULL) != 0) + return (NULL); + philo = init_chain_philo(params, m_print); if (philo == NULL) return (NULL); return (philo); diff --git a/srcs/main.c b/srcs/main.c index 1794140..f700eda 100644 --- a/srcs/main.c +++ b/srcs/main.c @@ -24,7 +24,6 @@ int main(int ac, char **av) if (philo == NULL) return (0); n = philo->params->n_phi; -// pthread_mutex_init(&mutex, NULL); create_threads(philo, id, n); i = 0; while (i < n)