aboutsummaryrefslogtreecommitdiff
path: root/philo_three
diff options
context:
space:
mode:
Diffstat (limited to 'philo_three')
-rw-r--r--philo_three/Makefile4
-rw-r--r--philo_three/src/child.c5
-rw-r--r--philo_three/src/event.c7
-rw-r--r--philo_three/src/main.c2
4 files changed, 11 insertions, 7 deletions
diff --git a/philo_three/Makefile b/philo_three/Makefile
index da20c9d..cac5e51 100644
--- a/philo_three/Makefile
+++ b/philo_three/Makefile
@@ -6,7 +6,7 @@
# By: cacharle <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/11/24 05:50:15 by cacharle #+# #+# #
-# Updated: 2021/01/08 14:32:09 by charles ### ########.fr #
+# Updated: 2021/01/08 15:03:18 by charles ### ########.fr #
# #
# **************************************************************************** #
@@ -17,7 +17,7 @@ MAKE = make --no-print-directory
COMMON_DIR = ../common
CC = gcc
-CCFLAGS = -std=c99 -Wall -Wextra -Werror -O2 -I$(COMMON_DIR)/inc
+CCFLAGS = -std=c99 -O2 -I$(COMMON_DIR)/inc -Wall -Wextra #-Werror
LDFLAGS = -lpthread -L$(COMMON_DIR) -lphilocommon
NAME = philo_three
diff --git a/philo_three/src/child.c b/philo_three/src/child.c
index 6060cf7..88a4b7c 100644
--- a/philo_three/src/child.c
+++ b/philo_three/src/child.c
@@ -6,7 +6,7 @@
/* By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/09/30 14:36:16 by cacharle #+# #+# */
-/* Updated: 2021/01/04 11:03:58 by cacharle ### ########.fr */
+/* Updated: 2021/01/08 15:42:02 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -63,10 +63,9 @@ pid_t child_start(t_philo *philo)
philo->sem_start = sem_open(PHILO_SEM_START_NAME, 0);
philo->time_last_eat = h_time_now();
pthread_create(&thread_death, NULL, (t_routine)routine_death, philo);
+ pthread_detach(thread_death);
event_think(philo);
sem_wait(philo->sem_start);
- if (philo->id % 2 == 0)
- usleep(500);
st_child_loop(philo);
exit(0);
}
diff --git a/philo_three/src/event.c b/philo_three/src/event.c
index 665f260..2a4ccf7 100644
--- a/philo_three/src/event.c
+++ b/philo_three/src/event.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/14 21:37:50 by cacharle #+# #+# */
-/* Updated: 2021/01/04 10:57:35 by cacharle ### ########.fr */
+/* Updated: 2021/01/08 15:13:02 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,6 +19,7 @@ void event_take_fork(t_philo *philo)
sem_wait(philo->sem_stdout);
philo_put(philo->id, EVENT_FORK, philo->initial_time);
philo_put(philo->id, EVENT_FORK, philo->initial_time);
+ philo_put_flush();
sem_post(philo->sem_stdout);
}
@@ -26,6 +27,7 @@ void event_eat(t_philo *philo)
{
sem_wait(philo->sem_stdout);
philo_put(philo->id, EVENT_EAT, philo->initial_time);
+ philo_put_flush();
sem_post(philo->sem_stdout);
h_sleep(philo->conf->timeout_eat);
}
@@ -34,6 +36,7 @@ void event_think(t_philo *philo)
{
sem_wait(philo->sem_stdout);
philo_put(philo->id, EVENT_THINK, philo->initial_time);
+ philo_put_flush();
sem_post(philo->sem_stdout);
}
@@ -41,6 +44,7 @@ void event_sleep(t_philo *philo)
{
sem_wait(philo->sem_stdout);
philo_put(philo->id, EVENT_SLEEP, philo->initial_time);
+ philo_put_flush();
sem_post(philo->sem_stdout);
sem_post(philo->forks);
sem_post(philo->forks);
@@ -53,6 +57,7 @@ void event_die(t_philo *philo)
sem_wait(philo->sem_stdout);
philo_put(philo->id, EVENT_DIE, philo->initial_time);
+ philo_put_flush();
if (philo->conf->meal_num == -1)
sem_post(philo->sem_finish);
else
diff --git a/philo_three/src/main.c b/philo_three/src/main.c
index 105903d..0b3397c 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/04 11:06:41 by cacharle ### ########.fr */
+/* Updated: 2021/01/08 15:11:05 by charles ### ########.fr */
/* */
/* ************************************************************************** */