diff --git a/data.c b/data.c index 8769c3a..6b1de35 100644 --- a/data.c +++ b/data.c @@ -6,13 +6,14 @@ #include "./data.h" #include "philo.h" #include "philos.h" -#include "struct.h" #include bool data_init(t_data *data) { + size_t i; + data->stop = 0; - data->forks = malloc(sizeof(bool) * data->nb_philos); + data->forks = malloc(sizeof(pthread_mutex_t) * data->nb_philos); if (data->forks == NULL) return (1); memset(data->forks, 1, data->nb_philos); @@ -29,7 +30,12 @@ bool data_init(t_data *data) free(data->forks); return (1); } - pthread_mutex_init(&data->forks_mutex, NULL); + i = 0; + while (i < data->nb_philos) + { + pthread_mutex_init(&data->forks[i], NULL); + i++; + } pthread_mutex_init(&data->stop_mutex, NULL); pthread_mutex_init(&data->print_mutex, NULL); return (0); @@ -52,7 +58,12 @@ void data_destroyer(t_data *data) i++; usleep(1000); } - pthread_mutex_destroy(&data->forks_mutex); + i = 0; + while (i < data->nb_philos) + { + pthread_mutex_destroy(&data->forks[i]); + i++; + } pthread_mutex_destroy(&data->stop_mutex); pthread_mutex_destroy(&data->print_mutex); free(data->threads);