This commit is contained in:
Etienne Rey-bethbeder 2023-04-08 19:41:07 +02:00
parent 61035874a8
commit c30de10070
2 changed files with 11 additions and 2 deletions

View file

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);

View file

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;