aboutsummaryrefslogtreecommitdiff
path: root/philo_three/src
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2021-01-10 13:34:50 +0100
committerCharles Cabergs <me@cacharle.xyz>2021-01-10 13:40:02 +0100
commitd552a2af95a3e03f937a94945369536d1eaae74a (patch)
treedcbc6bb1af33219730086cfb5ca1ce0b83a17187 /philo_three/src
parent5b03a0e341881ace66dc5cec5dcfba82fce8221d (diff)
downloadphilosophers-d552a2af95a3e03f937a94945369536d1eaae74a.tar.gz
philosophers-d552a2af95a3e03f937a94945369536d1eaae74a.tar.bz2
philosophers-d552a2af95a3e03f937a94945369536d1eaae74a.zip
Updated philo_two with better setup, Norming philo_two
Diffstat (limited to 'philo_three/src')
-rw-r--r--philo_three/src/child.c8
-rw-r--r--philo_three/src/main.c4
2 files changed, 7 insertions, 5 deletions
diff --git a/philo_three/src/child.c b/philo_three/src/child.c
index 63ec3e4..5516151 100644
--- a/philo_three/src/child.c
+++ b/philo_three/src/child.c
@@ -6,13 +6,13 @@
/* By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/09/30 14:36:16 by cacharle #+# #+# */
-/* Updated: 2021/01/10 10:39:19 by cacharle ### ########.fr */
+/* Updated: 2021/01/10 12:06:40 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "philo_three.h"
-void *routine_death(t_philo *philo)
+static void *st_routine_death(t_philo *philo)
{
while (true)
{
@@ -73,8 +73,10 @@ pid_t child_start(t_philo *philo)
philo->sem_eat = sem_open(sem_eat_name, O_CREAT | O_EXCL, 0700, 1);
sem_wait(philo->sem_start);
philo->time_last_eat = h_time_now();
- pthread_create(&thread_death, NULL, (t_routine)routine_death, philo);
+ if (pthread_create(&thread_death, NULL, (t_routine)st_routine_death, philo) != 0)
+ exit(1);
pthread_detach(thread_death);
+ philo->time_last_eat = h_time_now();
st_child_loop(philo);
exit(0);
}
diff --git a/philo_three/src/main.c b/philo_three/src/main.c
index 64b1004..e3f3022 100644
--- a/philo_three/src/main.c
+++ b/philo_three/src/main.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/15 00:45:24 by cacharle #+# #+# */
-/* Updated: 2021/01/09 15:57:47 by charles ### ########.fr */
+/* Updated: 2021/01/10 13:23:54 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -116,7 +116,7 @@ int main(int argc, char **argv)
if (conf.meal_num != -1)
{
pthread_t thread_meal_num;
- pthread_create(&thread_meal_num, NULL, (t_routine)st_routine_meal_num, (void*)&conf);
+ pthread_create(&thread_meal_num, NULL, (t_routine)st_routine_meal_num, &conf);
pthread_detach(thread_meal_num);
}
sem_wait(conf.sem_finish);