diff --git a/philo/manage_threads.c b/philo/manage_threads.c index 4fdfd0e..cae7655 100644 --- a/philo/manage_threads.c +++ b/philo/manage_threads.c @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/03/29 20:44:30 by erey-bet #+# #+# */ -/* Updated: 2023/04/08 16:07:07 by erey-bet ### ########.fr */ +/* Updated: 2023/04/08 19:40:03 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,14 +19,22 @@ static t_same *create_struct_same(t_config *config) same = ft_calloc(sizeof(t_same), 1); if (!same) return (NULL); + same->forks = ft_calloc(sizeof(int), config->nbr_philo + 1); + if (!same->forks) + { + free(same); + return (NULL); + } same->mutex = ft_calloc(sizeof(pthread_mutex_t), config->nbr_philo + 3); if (!same->mutex) { + free(same->forks); free(same); return (NULL); } if (init_mutex(same->mutex, config->nbr_philo + 3)) { + free(same->forks); free(same->mutex); free(same); return (NULL); diff --git a/philo/philo.h b/philo/philo.h index 2f46d58..492d268 100644 --- a/philo/philo.h +++ b/philo/philo.h @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/03/08 14:51:16 by erey-bet #+# #+# */ -/* Updated: 2023/04/08 16:40:38 by erey-bet ### ########.fr */ +/* Updated: 2023/04/08 19:38:07 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,6 +30,7 @@ typedef struct s_config typedef struct s_same { t_config *config; + int *forks; pthread_mutex_t *mutex; int all_eat; int death;