「🏗️」 wip: testing things, might broke.
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/11 14:36:59 by adjoly #+# #+# */
|
/* Created: 2024/07/11 14:36:59 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/07/25 15:14:45 by adjoly ### ########.fr */
|
/* Updated: 2024/07/25 16:18:55 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ void init_philo(t_pdata data)
|
|||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
pthread_mutex_init(&check, NULL);
|
pthread_mutex_init(&check, NULL);
|
||||||
init_fork(init, init[0].data.data.philo_nbr);
|
init_fork(init, data.philo_nbr);
|
||||||
while (i < data.philo_nbr)
|
while (i < data.philo_nbr)
|
||||||
{
|
{
|
||||||
init[i].data.id = i;
|
init[i].data.id = i;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/07 15:10:29 by adjoly #+# #+# */
|
/* Created: 2024/07/07 15:10:29 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/07/23 17:42:16 by adjoly ### ########.fr */
|
/* Updated: 2024/07/25 16:24:01 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -24,4 +24,5 @@ int main(int ac, char **av)
|
|||||||
if (data.error == true)
|
if (data.error == true)
|
||||||
return (EXIT_FAILURE);
|
return (EXIT_FAILURE);
|
||||||
init_philo(data);
|
init_philo(data);
|
||||||
|
return (EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/22 21:24:53 by adjoly #+# #+# */
|
/* Created: 2024/07/22 21:24:53 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/07/25 16:12:00 by adjoly ### ########.fr */
|
/* Updated: 2024/07/25 16:27:20 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -21,6 +21,7 @@ void *philo_routine(void *content)
|
|||||||
|
|
||||||
philo = *(t_philo *)content;
|
philo = *(t_philo *)content;
|
||||||
gettimeofday(&(philo.t0), NULL);
|
gettimeofday(&(philo.t0), NULL);
|
||||||
|
printf("asdf = %hhu\n", philo.data.meal_nbr);
|
||||||
while (i < philo.data.meal_nbr)
|
while (i < philo.data.meal_nbr)
|
||||||
{
|
{
|
||||||
philo.state = EAT;
|
philo.state = EAT;
|
||||||
@ -28,6 +29,8 @@ void *philo_routine(void *content)
|
|||||||
pthread_mutex_lock(philo.fork.right);
|
pthread_mutex_lock(philo.fork.right);
|
||||||
log_philo(philo);
|
log_philo(philo);
|
||||||
death = sleep_phil(philo.data.eat_time, philo.check);
|
death = sleep_phil(philo.data.eat_time, philo.check);
|
||||||
|
pthread_mutex_unlock(&philo.fork.left);
|
||||||
|
pthread_mutex_unlock(philo.fork.right);
|
||||||
if (death == true)
|
if (death == true)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
philo.state = SLEEP;
|
philo.state = SLEEP;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/24 18:19:14 by adjoly #+# #+# */
|
/* Created: 2024/07/24 18:19:14 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/07/24 23:01:29 by adjoly ### ########.fr */
|
/* Updated: 2024/07/25 16:28:27 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -23,6 +23,7 @@ void start_philo(t_init *init, uint16_t philo_nbr)
|
|||||||
r = pthread_join(init[i].thread, NULL);
|
r = pthread_join(init[i].thread, NULL);
|
||||||
if (r != 0)
|
if (r != 0)
|
||||||
return ;
|
return ;
|
||||||
|
usleep(500);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user