diff --git a/Makefile b/Makefile index 275f740..8752a49 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ NAME = philo CC = clang -CFLAGS = -Wall -Wextra $(INCLUDES) -g # add -Werror, del -g +CFLAGS = -Wall -Wextra -Werror $(INCLUDES) -g3 # del g3 VPATH = $(DIR_SRCS) DIR_SRCS = srcs diff --git a/headers/philo_struct.h b/headers/philo_struct.h index a57aa78..6d9440b 100644 --- a/headers/philo_struct.h +++ b/headers/philo_struct.h @@ -17,7 +17,7 @@ typedef struct s_philo t_params *params; int philo_nbr; int fork; - t_mtx *msg_mtx; + t_mtx *m_print; struct s_philo *prev; struct s_philo *next; } t_philo; diff --git a/srcs/exec.c b/srcs/exec.c index 481c335..583844a 100644 --- a/srcs/exec.c +++ b/srcs/exec.c @@ -24,11 +24,9 @@ void *philo_exec(void *arg) philo = (t_philo*)arg; nbr = philo->philo_nbr; - pthread_mutex_lock(philo->msg_mtx); -// pthread_mutex_lock(&mutex); - ft_printf("%i is thinking\n", philo->philo_nbr); - pthread_mutex_unlock(philo->msg_mtx); -// pthread_mutex_unlock(&mutex); +pthread_mutex_lock(philo->m_print); +ft_printf("%i is thinking\n", philo->philo_nbr); +pthread_mutex_unlock(philo->m_print); // eat // "has taken a fork" diff --git a/srcs/init.c b/srcs/init.c index 5c6d5a0..da20d78 100644 --- a/srcs/init.c +++ b/srcs/init.c @@ -1,6 +1,6 @@ #include "philo.h" -t_philo *create_each_philo(t_philo *philo, t_params *params, t_mtx *mtx, int i) +t_philo *lst_add_philo(t_philo *philo, t_params *params, t_mtx *m_print, int i) { t_philo *new; @@ -10,7 +10,7 @@ t_philo *create_each_philo(t_philo *philo, t_params *params, t_mtx *mtx, int i) new->params = params; new->philo_nbr = i + 1; new->fork = 1; - new->msg_mtx = mtx; + new->m_print = m_print; if (philo) philo->next = new; new->prev = philo; @@ -18,7 +18,7 @@ t_philo *create_each_philo(t_philo *philo, t_params *params, t_mtx *mtx, int i) } // looping chained list -t_philo *init_chain_philo(t_params *params, t_mtx *mutex) +t_philo *init_chain_philo(t_params *params, t_mtx *m_print) { t_philo *end; t_philo *philo; @@ -28,7 +28,7 @@ t_philo *init_chain_philo(t_params *params, t_mtx *mutex) philo = NULL; while (i < params->n_phi) { - philo = create_each_philo(philo, params, mutex, i); + philo = lst_add_philo(philo, params, m_print, i); i++; } end = philo; @@ -67,10 +67,10 @@ t_philo *init(int ac, char **av, pthread_t **id) params = init_params(ac, av); if (params == NULL) return (NULL); - *id = malloc(sizeof(int) * params->n_phi); + *id = malloc(sizeof(pthread_t) * params->n_phi); if (*id == NULL) return (NULL); - m_print = NULL; + m_print = malloc(sizeof(t_mtx)); if (pthread_mutex_init(m_print, NULL) != 0) return (NULL); philo = init_chain_philo(params, m_print); diff --git a/srcs/main.c b/srcs/main.c index f700eda..a0ae8df 100644 --- a/srcs/main.c +++ b/srcs/main.c @@ -1,6 +1,6 @@ #include "philo.h" -void create_threads(t_philo *philo, pthread_t *id, int n) +void launch_threads(t_philo *philo, pthread_t *id, int n) { int i; @@ -24,7 +24,7 @@ int main(int ac, char **av) if (philo == NULL) return (0); n = philo->params->n_phi; - create_threads(philo, id, n); + launch_threads(philo, id, n); i = 0; while (i < n) {