fix: I create now 1 thread by philo
This commit is contained in:
6
data.c
6
data.c
@ -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);
|
||||
|
Reference in New Issue
Block a user