From: Lukas Jiriste Date: Fri, 24 May 2024 07:22:59 +0000 (+0200) Subject: Rename philo attribute lives to alive, minor fixes X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=b6cb5048195b5ae512dc5a790da9198426a88b45;p=42%2Fphilosophers.git Rename philo attribute lives to alive, minor fixes The attribute has not been initialized in previous commits. It has aso not been a part of the philosopher structure... This has been rectified. --- diff --git a/philo_bonus/helpers.c b/philo_bonus/helpers.c index 02c3e97..20dfa30 100644 --- a/philo_bonus/helpers.c +++ b/philo_bonus/helpers.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/09 09:13:40 by ljiriste #+# #+# */ -/* Updated: 2024/05/12 21:54:46 by ljiriste ### ########.fr */ +/* Updated: 2024/05/24 09:21:50 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,7 +28,7 @@ int is_alive(t_philo *philo) int res; sem_wait(philo->philo_sem); - res = philo->lives; + res = philo->alive; sem_post(philo->philo_sem); return (res); } diff --git a/philo_bonus/main.c b/philo_bonus/main.c index 36e1cd2..48f6e42 100644 --- a/philo_bonus/main.c +++ b/philo_bonus/main.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/22 11:19:48 by ljiriste #+# #+# */ -/* Updated: 2024/05/12 21:48:59 by ljiriste ### ########.fr */ +/* Updated: 2024/05/24 09:21:34 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,6 +27,7 @@ static int seat_philosophers(t_settings *settings, pid_t *philo_pids) gettimeofday(&settings->start, NULL); philo.settings = *settings; philo.id = 1; + philo.alive = 1; while (philo.id <= settings->philo_count) { philo_pids[philo.id - 1] = fork(); diff --git a/philo_bonus/philo.h b/philo_bonus/philo.h index 1f114a8..625c60f 100644 --- a/philo_bonus/philo.h +++ b/philo_bonus/philo.h @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/22 11:10:17 by ljiriste #+# #+# */ -/* Updated: 2024/05/12 21:55:26 by ljiriste ### ########.fr */ +/* Updated: 2024/05/24 09:21:24 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -58,6 +58,7 @@ typedef struct s_philosopher { unsigned int num_eaten; unsigned int id; + int alive; useconds_t last_eaten; sem_t *semaphores[sem_num]; sem_t *philo_sem;