「🏗️」 wip: testing things, might broke.
This commit is contained in:
@ -1,27 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* init_fork.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/16 19:53:01 by adjoly #+# #+# */
|
||||
/* Updated: 2024/07/18 21:03:00 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
void init_fork(t_philo *philo, t_pdata data)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (philo[i] && i <= data.philo_nbr)
|
||||
{
|
||||
pthread_mutex_init(philo[i].fork.left);
|
||||
if (i == data.philo_nbr)
|
||||
philo[i].fork.right = &philo[0].fork.left;
|
||||
else
|
||||
philo[i].fork.right = &philo[i + 1].fork.left;
|
||||
i++;
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/11 14:36:59 by adjoly #+# #+# */
|
||||
/* Updated: 2024/07/17 22:53:48 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/07/22 14:05:52 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,21 +14,22 @@
|
||||
|
||||
void init_philo(t_pdata data)
|
||||
{
|
||||
t_philo philo[PHILO_MAX];
|
||||
t_philo *tmp;
|
||||
t_init init[PHILO_MAX];
|
||||
pthread_mutex_t *print;
|
||||
int ret;
|
||||
|
||||
tmp = philo;
|
||||
i = 0;
|
||||
init_fork(philo, data);
|
||||
while (tmp && i < data->philo_nbr)
|
||||
while (i < data->philo_nbr)
|
||||
{
|
||||
ret = pthread_create(&(tmp->thread), NULL, philo_routine, tmp);
|
||||
ret = pthread_create(&(init[i]->thread), NULL, philo_routine, tmp);
|
||||
if (ret != 0)
|
||||
return ;
|
||||
tmp->data = data;
|
||||
tmp->state = EAT;
|
||||
tmp++;
|
||||
init[i]->philo->nbr = i;
|
||||
gettimeofday(&(init[i]->philo->t0), NULL)
|
||||
init[i]->philo->data = data;
|
||||
init[i]->philo->state = EAT;
|
||||
init[i]->philo->fork = init_fork(init, i, data->philo_nbr);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/07 15:11:02 by adjoly #+# #+# */
|
||||
/* Updated: 2024/07/21 21:55:26 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/07/22 14:01:27 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -69,14 +69,11 @@ t_pdata philo_parse(char **argv, int ac);
|
||||
long long ft_atoll(const char *nptr);
|
||||
uint16_t get_time_in_ms(struct timeval t0, struct timeval t1);
|
||||
|
||||
void *philo_routine(void *param);
|
||||
/**
|
||||
* Main path
|
||||
* by order of call
|
||||
*/
|
||||
t_philo *init_philo(t_pdata data, uint16_t philo_nbr);
|
||||
void init_fork(t_philo *philo, t_pdata data);
|
||||
void start_philo(t_philo *philo, t_pdata data);
|
||||
|
||||
/**
|
||||
* For debug purpose to be REMOVED
|
||||
|
@ -1,19 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* philo_routine.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/16 19:54:02 by adjoly #+# #+# */
|
||||
/* Updated: 2024/07/16 20:57:54 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
void *philo_routine(void *param)
|
||||
{
|
||||
t_philo philo;
|
||||
|
||||
philo = (t_philo)param;
|
||||
log
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* start_philo.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/18 18:31:21 by adjoly #+# #+# */
|
||||
/* Updated: 2024/07/18 19:08:43 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
void start_philo(t_philo *philo, t_pdata data)
|
||||
{
|
||||
int i;
|
||||
int ret;
|
||||
|
||||
i = 0;
|
||||
while (philo[i] && i < data.philo_nbr)
|
||||
{
|
||||
ret = pthread_join(&(philo->thread), NULL);
|
||||
if (ret != 0)
|
||||
return ;
|
||||
i++;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user