From df7c2f7bf3748e276e71dd409590b59e5b9590e1 Mon Sep 17 00:00:00 2001 From: Danny Jonker Date: Sat, 20 May 2023 10:08:26 +0200 Subject: [PATCH] almost --- philo/Makefile | 4 ++-- philo/src/philo.c | 4 ++-- philo/src/util.c | 17 ++++++++++++----- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/philo/Makefile b/philo/Makefile index 2e930b2..72f7765 100644 --- a/philo/Makefile +++ b/philo/Makefile @@ -6,13 +6,13 @@ # By: djonker // \ \ __| | | \ \/ / # # (| | )|_| |_| |> < # # Created: 2021/08/19 15:20:20 by djonker /'\_ _/`\__|\__,_/_/\_\ # -# Updated: 2023/05/20 08:42:21 by djonker \___)=(___/ # +# Updated: 2023/05/20 09:36:06 by djonker \___)=(___/ # # # # **************************************************************************** # NAME =philo CC =gcc -CFLAGS =-Wall -Werror -Wextra -g -fsanitize=thread +CFLAGS =-Wall -Werror -Wextra# -g -fsanitize=thread RM =rm -f SRC =src/philo.c\ src/init.c\ diff --git a/philo/src/philo.c b/philo/src/philo.c index 9224ee4..852aed3 100644 --- a/philo/src/philo.c +++ b/philo/src/philo.c @@ -6,7 +6,7 @@ /* By: houtworm // \ \ __| | | \ \/ / */ /* (| | )|_| |_| |> < */ /* Created: 2023/03/11 06:42:31 by houtworm /'\_ _/`\__|\__,_/_/\_\ */ -/* Updated: 2023/05/20 09:08:25 by djonker \___)=(___/ */ +/* Updated: 2023/05/20 09:47:03 by djonker \___)=(___/ */ /* */ /* ************************************************************************** */ @@ -47,7 +47,7 @@ void *ft_cycle(void *pointer) philo = pointer; if ((philo->id - 1) % 2) - usleep(*philo->eattime * 900); + usleep(*philo->eattime * 1000); pthread_mutex_lock(philo->drdead); while (*philo->dead == 0) { diff --git a/philo/src/util.c b/philo/src/util.c index 995d0fb..6c01448 100644 --- a/philo/src/util.c +++ b/philo/src/util.c @@ -6,7 +6,7 @@ /* By: houtworm // \ \ __| | | \ \/ / */ /* (| | )|_| |_| |> < */ /* Created: 2023/03/15 02:01:41 by houtworm /'\_ _/`\__|\__,_/_/\_\ */ -/* Updated: 2023/05/20 08:27:44 by djonker \___)=(___/ */ +/* Updated: 2023/05/20 10:04:39 by djonker \___)=(___/ */ /* */ /* ************************************************************************** */ @@ -83,11 +83,18 @@ int ft_cleanup(t_strct *strct) void ft_aliveprint(t_philo *ps, char *str) { pthread_mutex_lock(ps->drdead); - if (!*ps->dead) + if (*ps->dead) { pthread_mutex_unlock(ps->drdead); - printf("%lld %d %s\n", ft_time() - *ps->strtt, ps->id, str); + return ; } - else - pthread_mutex_unlock(ps->drdead); + pthread_mutex_unlock(ps->drdead); + printf("%lld %d %s\n", ft_time() - *ps->strtt, ps->id, str); } + + + /*• Test 1 800 200 200. The philosopher should not eat and should die.*/ + /*• Test 5 800 200 200. No philosopher should die.*/ + /*• Test 5 800 200 200 7. No philosopher should die and the simulation should stop when every philosopher has eaten at least 7 times.*/ + /*• Test 4 410 200 200. No philosopher should die.*/ + /*• Test 4 310 200 100. One philosopher should die.*/