2023-04-13 09:00:39 -04:00
|
|
|
#ifndef STRUCT_H
|
|
|
|
# define STRUCT_H
|
|
|
|
# include <pthread.h>
|
|
|
|
# include <stddef.h>
|
|
|
|
# include <sys/types.h>
|
|
|
|
|
|
|
|
typedef struct s_data
|
|
|
|
{
|
|
|
|
size_t eat_time;
|
|
|
|
size_t sleep_time;
|
|
|
|
size_t life_expectency;
|
|
|
|
size_t nb_philos;
|
|
|
|
ssize_t nb_meals;
|
|
|
|
void **philos;
|
|
|
|
pthread_t *threads;
|
|
|
|
pthread_mutex_t forks_mutex;
|
|
|
|
bool *forks;
|
|
|
|
pthread_mutex_t stop_mutex;
|
|
|
|
bool stop;
|
2023-04-20 08:40:30 -04:00
|
|
|
pthread_mutex_t print_mutex;
|
2023-04-13 09:00:39 -04:00
|
|
|
} t_data;
|
|
|
|
|
|
|
|
typedef struct s_philo
|
|
|
|
{
|
|
|
|
size_t id;
|
|
|
|
pthread_mutex_t nb_meal_mutex;
|
|
|
|
size_t nb_meal;
|
|
|
|
pthread_mutex_t last_eat_mutex;
|
|
|
|
size_t last_eat;
|
|
|
|
pthread_mutex_t last_sleep_mutex;
|
|
|
|
size_t last_sleep;
|
2023-04-19 10:01:59 -04:00
|
|
|
pthread_mutex_t stop_mutex;
|
|
|
|
bool stop;
|
2023-04-13 09:00:39 -04:00
|
|
|
t_data *data;
|
|
|
|
} t_philo;
|
|
|
|
|
|
|
|
t_philo *philo_create(t_data *data);
|
|
|
|
t_philo *philo_destoyer(t_philo *philo);
|
|
|
|
void *philo_routine(void *arg);
|
|
|
|
|
|
|
|
#endif
|