aboutsummaryrefslogtreecommitdiff
path: root/philo_three/src/main.c
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2021-01-03 14:04:22 +0100
committerCharles Cabergs <me@cacharle.xyz>2021-01-03 14:04:22 +0100
commite874ad94a31a8259b8eb7ad2865767c081bcd279 (patch)
treee629a6cef53b2c6cafcde9f8bbf5d1f7678753d6 /philo_three/src/main.c
parent592c515b742222c637478b3339b95cd2de8b4379 (diff)
downloadphilosophers-e874ad94a31a8259b8eb7ad2865767c081bcd279.tar.gz
philosophers-e874ad94a31a8259b8eb7ad2865767c081bcd279.tar.bz2
philosophers-e874ad94a31a8259b8eb7ad2865767c081bcd279.zip
Fixing philo_one/philo_two dying by sleeping more when checking the death, Fixing timestamp in the wrong order in philo_three
Diffstat (limited to 'philo_three/src/main.c')
-rw-r--r--philo_three/src/main.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/philo_three/src/main.c b/philo_three/src/main.c
index 9597fc0..8a5dec4 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/02 12:49:44 by cacharle ### ########.fr */
+/* Updated: 2021/01/03 14:01:58 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -38,14 +38,14 @@ static int st_destroy(t_sems *sems, pid_t *pids, int philo_num)
return (1);
}
-static int st_setup(t_philo_args *args, t_sems *sems, pid_t **pids)
+static int st_setup(
+ t_philo_args *args, t_sems *sems, pid_t **pids, t_time initial_time)
{
t_philo philo;
int i;
sems->sem_stdout = SEM_FAILED;
sems->sem_finish = SEM_FAILED;
- *pids = NULL;
if ((sems->forks =
st_sem_create(PHILO_SEM_NAME, args->philo_num)) == SEM_FAILED
|| (sems->sem_stdout =
@@ -60,6 +60,7 @@ static int st_setup(t_philo_args *args, t_sems *sems, pid_t **pids)
{
philo.conf = args;
philo.id = i + 1;
+ philo.initial_time = initial_time;
if (((*pids)[i] = child_start(&philo)) == -1)
return (st_destroy(sems, *pids, i));
usleep(200);
@@ -97,7 +98,8 @@ int main(int argc, char **argv)
return (1);
if (args.philo_num == 0 || args.meal_num == 0)
return (0);
- if (st_setup(&args, &sems, &pids) != 0)
+ pids = NULL;
+ if (st_setup(&args, &sems, &pids, h_time_now()) != 0)
return (1);
st_wait(&args, &sems);
st_destroy(&sems, pids, args.philo_num);