From 07c287be1a19c225a8ffe68203777d848bfa1dbd Mon Sep 17 00:00:00 2001 From: Adam Joly Date: Thu, 25 Jul 2024 16:31:28 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=8F=97=EF=B8=8F=E3=80=8D=20wip:?= =?UTF-8?q?=20testing=20things,=20might=20broke.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- philo/init_philo.c | 4 ++-- philo/philo.c | 3 ++- philo/philo_routine.c | 5 ++++- philo/start_philo.c | 3 ++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/philo/init_philo.c b/philo/init_philo.c index b0c3e71..9bc9516 100644 --- a/philo/init_philo.c +++ b/philo/init_philo.c @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/11 14:36:59 by adjoly #+# #+# */ -/* Updated: 2024/07/25 15:14:45 by adjoly ### ########.fr */ +/* Updated: 2024/07/25 16:18:55 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ void init_philo(t_pdata data) i = 0; pthread_mutex_init(&check, NULL); - init_fork(init, init[0].data.data.philo_nbr); + init_fork(init, data.philo_nbr); while (i < data.philo_nbr) { init[i].data.id = i; diff --git a/philo/philo.c b/philo/philo.c index 2b34ad9..268ac04 100644 --- a/philo/philo.c +++ b/philo/philo.c @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/07 15:10:29 by adjoly #+# #+# */ -/* Updated: 2024/07/23 17:42:16 by adjoly ### ########.fr */ +/* Updated: 2024/07/25 16:24:01 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,4 +24,5 @@ int main(int ac, char **av) if (data.error == true) return (EXIT_FAILURE); init_philo(data); + return (EXIT_SUCCESS); } diff --git a/philo/philo_routine.c b/philo/philo_routine.c index cfd9bcf..164f245 100644 --- a/philo/philo_routine.c +++ b/philo/philo_routine.c @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/22 21:24:53 by adjoly #+# #+# */ -/* Updated: 2024/07/25 16:12:00 by adjoly ### ########.fr */ +/* Updated: 2024/07/25 16:27:20 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,6 +21,7 @@ void *philo_routine(void *content) philo = *(t_philo *)content; gettimeofday(&(philo.t0), NULL); + printf("asdf = %hhu\n", philo.data.meal_nbr); while (i < philo.data.meal_nbr) { philo.state = EAT; @@ -28,6 +29,8 @@ void *philo_routine(void *content) pthread_mutex_lock(philo.fork.right); log_philo(philo); death = sleep_phil(philo.data.eat_time, philo.check); + pthread_mutex_unlock(&philo.fork.left); + pthread_mutex_unlock(philo.fork.right); if (death == true) return (NULL); philo.state = SLEEP; diff --git a/philo/start_philo.c b/philo/start_philo.c index 251099e..0489b30 100644 --- a/philo/start_philo.c +++ b/philo/start_philo.c @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/24 18:19:14 by adjoly #+# #+# */ -/* Updated: 2024/07/24 23:01:29 by adjoly ### ########.fr */ +/* Updated: 2024/07/25 16:28:27 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,6 +23,7 @@ void start_philo(t_init *init, uint16_t philo_nbr) r = pthread_join(init[i].thread, NULL); if (r != 0) return ; + usleep(500); i++; } }