22#include "../philosopher/philo.h"
36 usleep((global->opt.tt_eat + global->opt.tt_sleep)
37 * (global->opt.eat_n - 1) * 1000);
40 pthread_mutex_lock(&thread[i].full);
41 pthread_mutex_unlock(&thread[i].full);
42 pthread_mutex_destroy(&thread[i].full);
61 while (i < global->opt.n && !res)
64 thread[i++].global = global;
65 if (pthread_create(&thread[i - 1].thread, 0,
73 if (global->opt.eat_n)
77 if (pthread_join(thread[i].thread, 0) || thread[i].
err)
98 if (!
setup(&global, &thread))
101 pthread_mutex_destroy(&global.printing);
102 pthread_mutex_destroy(&global.end_mutex);
105 pthread_mutex_destroy(&global.forks[i++]);
int err(const char *str, int retval)
Write str to stderr and return retval.
static int create_threads(t_global *global, t_thread *thread)
Spawn philos and wait for them to complete.
void * breakfast(void *data)
Ponder, eat, sleep, repeat.
static void monitor_eat_quota(t_global *global, t_thread *thread, int i)
End simulation once all philos are full.
int setup(t_global *global, t_thread **thread)
Allocate fork array and thread structure, initialize mutexes.
int seat(t_opt opt)
Allocate for, initialize, seat, wait on (pun intended), and free all philos.