aboutsummaryrefslogtreecommitdiff
path: root/philo_three/src/philo_three.h
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2021-01-09 16:07:01 +0100
committerCharles Cabergs <me@cacharle.xyz>2021-01-09 16:07:01 +0100
commit802ea8347d1ceb7a02cf279359b3b101106fab94 (patch)
tree3f8b38056e29d94a813351fb99cc911d89f8df3d /philo_three/src/philo_three.h
parentebbd81e4312d945b359d2761acfeb613da1f98c8 (diff)
downloadphilosophers-802ea8347d1ceb7a02cf279359b3b101106fab94.tar.gz
philosophers-802ea8347d1ceb7a02cf279359b3b101106fab94.tar.bz2
philosophers-802ea8347d1ceb7a02cf279359b3b101106fab94.zip
Added separate thread to check if max meal num is reached independent from philosopher death
Diffstat (limited to 'philo_three/src/philo_three.h')
-rw-r--r--philo_three/src/philo_three.h35
1 files changed, 22 insertions, 13 deletions
diff --git a/philo_three/src/philo_three.h b/philo_three/src/philo_three.h
index f2b841d..18c7bcb 100644
--- a/philo_three/src/philo_three.h
+++ b/philo_three/src/philo_three.h
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/15 00:46:26 by cacharle #+# #+# */
-/* Updated: 2021/01/08 20:25:00 by charles ### ########.fr */
+/* Updated: 2021/01/09 15:47:32 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -23,33 +23,42 @@
# include "common.h"
-# define PHILO_SEM_NAME "semaphore_philo_three"
-# define PHILO_SEM_STDOUT_NAME "semaphore_philo_three_stdout"
-# define PHILO_SEM_FINISH_NAME "semaphore_philo_three_finish"
-# define PHILO_SEM_START_NAME "semaphore_philo_three_start"
-# define PHILO_SEM_GRAB_NAME "semaphore_philo_three_grab"
+# define PHILO_SEM_NAME "semaphore_philo_three"
+# define PHILO_SEM_STDOUT_NAME "semaphore_philo_three_stdout"
+# define PHILO_SEM_FINISH_NAME "semaphore_philo_three_finish"
+# define PHILO_SEM_MEAL_NUM_NAME "semaphore_philo_three_meal_num"
+# define PHILO_SEM_START_NAME "semaphore_philo_three_start"
+# define PHILO_SEM_GRAB_NAME "semaphore_philo_three_grab"
-typedef struct s_philo
+typedef struct s_philo_conf
{
- t_philo_args *conf;
- int id;
- t_time time_last_eat;
+ long int philo_num;
+ t_time timeout_death;
+ t_time timeout_eat;
+ t_time timeout_sleep;
+ long int meal_num;
t_time initial_time;
sem_t *forks;
sem_t *sem_stdout;
sem_t *sem_finish;
+ sem_t *sem_meal_num;
sem_t *sem_start;
sem_t *sem_grab;
-} t_philo;
+} t_philo_conf;
-typedef struct s_sems
+typedef struct s_philo
{
+ t_philo_conf *conf;
+ int id;
+ t_time time_last_eat;
+ t_time initial_time;
sem_t *forks;
sem_t *sem_stdout;
sem_t *sem_finish;
+ sem_t *sem_meal_num;
sem_t *sem_start;
sem_t *sem_grab;
-} t_sems;
+} t_philo;
pid_t child_start(t_philo *arg);