philosopher/mandatory/utils_manage_threads.c
Etienne Rey-bethbeder ffb68409b1 Finito philo
2023-03-31 18:23:57 +02:00

51 lines
1.4 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils_manage_threads.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/30 01:04:41 by erey-bet #+# #+# */
/* Updated: 2023/03/31 17:51:30 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "philo.h"
void init_mutex(pthread_mutex_t *mutex, int nbr)
{
int i;
i = -1;
while (++i < nbr)
pthread_mutex_init(&mutex[i], NULL);
}
void destroy_mutex(pthread_mutex_t *mutex, int nbr)
{
int i;
i = -1;
while (++i < nbr)
pthread_mutex_destroy(&mutex[i]);
}
void free_all(pthread_t *threads, t_same *same, t_philo **philo)
{
int i;
destroy_mutex(same->mutex, 3);
free(threads);
free(same->mutex);
free(same->death);
free(same->all_eat);
free(same);
i = -1;
while (philo[++i])
{
free(philo[i]->only);
free(philo[i]);
}
free(philo);
}