Rename philo attribute lives to alive, minor fixes
authorLukas Jiriste <ljiriste@student.42prague.com>
Fri, 24 May 2024 07:22:59 +0000 (09:22 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Fri, 24 May 2024 07:22:59 +0000 (09:22 +0200)
The attribute has not been initialized in previous commits.
It has aso not been a part of the philosopher structure...
This has been rectified.

philo_bonus/helpers.c
philo_bonus/main.c
philo_bonus/philo.h

index 02c3e977ce5d469c2ed2fcfc0f3c81684a89ee99..20dfa3058d09f31d00fa29a4030c9f095ceebbef 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   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);
 }
index 36e1cd290a37692b5cc8974f9e85a3283d391eaf..48f6e4228c4fcfb4f3a5d33898ee3daca449b8ef 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   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();
index 1f114a85184af497e739dcc8ab85fc0f9037474c..625c60fa73b715e5638797c7c1d889839afffc9d 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   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;