fix: I create now 1 thread by philo

This commit is contained in:
Camille Chauvet
2023-04-19 11:53:50 +00:00
parent a37cbf88f3
commit 4e27d103a8
6 changed files with 42 additions and 24 deletions

6
data.c
View File

@ -6,12 +6,14 @@
#include "philo.h"
#include "philos.h"
#include "struct.h"
#include <string.h>
bool data_init(t_data *data)
{
data->forks = malloc(sizeof(bool) * data->nb_philos);
if (data->forks == NULL)
return (1);
memset(data->forks, 1, data->nb_philos);
data->philos = malloc(sizeof(t_philo) * data->nb_philos);
if (data->philos == NULL)
{
@ -25,8 +27,9 @@ bool data_init(t_data *data)
free(data->forks);
return (1);
}
pthread_mutex_init(&data->forks_mutex, NULL);
pthread_mutex_init(&data->stop_mutex, NULL);
data->stop = 0;
data->nb_meals = 0;
return (0);
}
@ -34,7 +37,6 @@ void data_destroyer(t_data *data)
{
free(data->threads);
free(data->forks);
pthread_mutex_destroy(&data->nb_meal_mutex);
pthread_mutex_destroy(&data->forks_mutex);
pthread_mutex_destroy(&data->stop_mutex);
philos_destroyer(data);