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++; } }