philosophers/philo/src/create_threads.c

33 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: o_ :::::: ::: */
/* create_threads.c :+: / :+::+: :+: */
/* +:+ > +:++:+ +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2025/01/20 14:26:45 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2025/01/20 14:27:37 by whaffman ### ### ### ### / \ */
/* */
/* ************************************************************************** */
#include "philo.h"
int create_threads(t_rules *rules)
{
int i;
t_philo *philo;
i = 0;
while (i < rules->n_philos)
{
philo = &rules->philos[i];
philo->pid = malloc(sizeof(pthread_t));
if (!philo->pid)
return (FAILURE);
if (pthread_create(philo->pid, NULL, &philo_routine, philo))
return (FAILURE);
i++;
}
return (SUCCESS);
}