init mutex broken

This commit is contained in:
hugogogo
2022-01-13 09:56:09 +01:00
parent bc40b571e9
commit f8f509dd59
3 changed files with 5 additions and 6 deletions

View File

@@ -1,8 +1,6 @@
#ifndef PHILO_PROTO_H #ifndef PHILO_PROTO_H
# define PHILO_PROTO_H # define PHILO_PROTO_H
// t_mtx mutex;
// init.c // init.c
t_philo *init(int ac, char **av, pthread_t **id); t_philo *init(int ac, char **av, pthread_t **id);

View File

@@ -62,7 +62,7 @@ t_philo *init(int ac, char **av, pthread_t **id)
{ {
t_philo *philo; t_philo *philo;
t_params *params; t_params *params;
t_mtx msg_mtx; t_mtx *m_print;
params = init_params(ac, av); params = init_params(ac, av);
if (params == NULL) if (params == NULL)
@@ -70,8 +70,10 @@ t_philo *init(int ac, char **av, pthread_t **id)
*id = malloc(sizeof(int) * params->n_phi); *id = malloc(sizeof(int) * params->n_phi);
if (*id == NULL) if (*id == NULL)
return (NULL); return (NULL);
pthread_mutex_init(&msg_mtx, NULL); m_print = NULL;
philo = init_chain_philo(params, &msg_mtx); if (pthread_mutex_init(m_print, NULL) != 0)
return (NULL);
philo = init_chain_philo(params, m_print);
if (philo == NULL) if (philo == NULL)
return (NULL); return (NULL);
return (philo); return (philo);

View File

@@ -24,7 +24,6 @@ int main(int ac, char **av)
if (philo == NULL) if (philo == NULL)
return (0); return (0);
n = philo->params->n_phi; n = philo->params->n_phi;
// pthread_mutex_init(&mutex, NULL);
create_threads(philo, id, n); create_threads(philo, id, n);
i = 0; i = 0;
while (i < n) while (i < n)