tgrekov-philosophers
HIVE philosophers July 2024
Loading...
Searching...
No Matches
philo.h
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* philo.h :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: tgrekov <tgrekov@student.hive.fi> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/07/22 04:59:35 by tgrekov #+# #+# */
9/* Updated: 2024/08/06 17:14:22 by tgrekov ### ########.fr */
10/* */
11/* ************************************************************************** */
12
20#ifndef PHILO_H
21# define PHILO_H
22
23# include <pthread.h>
24
25typedef struct s_opt
26{
27 int n;
28 int tt_die;
29 int tt_eat;
30 int tt_sleep;
31 int eat_n;
32} t_opt;
33
34typedef struct t_global
35{
36 t_opt opt;
37 pthread_mutex_t printing;
38 pthread_mutex_t *forks;
39 pthread_mutex_t end_mutex;
40 int end;
41} t_global;
42
43typedef struct s_thread
44{
45 int i;
46 pthread_t thread;
47 int err;
48 int last_meal;
49 int times_ate;
50 pthread_mutex_t full;
51 t_global *global;
52} t_thread;
53
54int philo_sleep(unsigned long ms, t_thread *thread);
55int status(t_thread *thread, char *str, int ignore_end);
56int check_end(t_global *global);
57int set_end(t_global *global);
58int stop(t_thread *thread);
59
60#endif
int check_end(t_global *global)
Check if the simulation has ended.
Definition sim_end.c:28
int philo_sleep(unsigned long ms, t_thread *thread)
Sleep in 200 microsecond intervals until ms millis have elapsed, or stop has returned non-zero.
Definition philo_sleep.c:33
int stop(t_thread *thread)
Determine if this thread's philo should die, or if the thread has reported an error.
Definition stop.c:30
int status(t_thread *thread, char *str, int ignore_end)
Thread safe philosopher state logging.
Definition status.c:46
Definition philo.h:26