2023-04-27 08:05:14 -04:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* ::: :::::::: */
|
|
|
|
/* threads.c :+: :+: :+: */
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
/* Created: 2023/04/27 11:33:45 by cchauvet #+# #+# */
|
|
|
|
/* Updated: 2023/04/27 11:37:40 by cchauvet ### ########.fr */
|
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
2023-04-13 09:00:39 -04:00
|
|
|
#include "philo.h"
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <stdbool.h>
|
2023-04-19 07:53:50 -04:00
|
|
|
#include <unistd.h>
|
2023-04-13 09:00:39 -04:00
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
bool threads_init(t_data *data)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < data->nb_philos)
|
|
|
|
{
|
2023-04-27 08:05:14 -04:00
|
|
|
if (pthread_create(&data->threads[i], NULL, philo_routine,
|
|
|
|
data->philos[i]))
|
2023-04-13 09:00:39 -04:00
|
|
|
return (true);
|
|
|
|
pthread_detach(data->threads[i]);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return (false);
|
|
|
|
}
|