21#include "../philosopher/philo.h"
33 global->forks = malloc(
sizeof(pthread_mutex_t) * global->opt.n);
36 *thread = malloc(
sizeof(
t_thread) * global->opt.n);
54 while (i < global->opt.n && !pthread_mutex_init(&global->forks[i], 0))
56 if (i == global->opt.n)
58 if (!global->opt.eat_n)
61 while (i < global->opt.n && !pthread_mutex_init(&thread[i].full, 0))
63 if (i == global->opt.n)
67 pthread_mutex_destroy(&thread[i].full);
68 i = global->opt.n - 1;
72 pthread_mutex_destroy(&global->forks[i]);
88 if (pthread_mutex_init(&global->printing, 0))
90 if (!pthread_mutex_init(&global->end_mutex, 0))
94 pthread_mutex_destroy(&global->end_mutex);
96 pthread_mutex_destroy(&global->printing);
static int initialize(t_global *global, t_thread *thread)
Initialize forks and eating quota mutexes.
static int allocate(t_global *global, t_thread **thread)
Allocate fork and thread arrays.
int setup(t_global *global, t_thread **thread)
Allocate fork array and thread structure, initialize mutexes.