Passing the norm on all these files
This commit is contained in:
parent
124064556e
commit
af63bafed0
7 changed files with 102 additions and 73 deletions
|
|
@ -6,12 +6,60 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/04 11:30:25 by rparodi #+# #+# */
|
||||
/* Updated: 2024/06/16 12:22:40 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/07/04 15:27:12 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/philo.h"
|
||||
|
||||
void *ft_routine(void *ptr)
|
||||
{
|
||||
t_philo *philo;
|
||||
|
||||
philo = (t_philo *) ptr;
|
||||
if (philo == NULL)
|
||||
return (NULL);
|
||||
while (!dead_loop(philo))
|
||||
{
|
||||
ft_start_eating(philo);
|
||||
ft_sleeping(philo);
|
||||
ft_thinking(philo);
|
||||
}
|
||||
return (philo);
|
||||
}
|
||||
|
||||
t_error ft_init_thread(t_program *prog, t_mutex *forks)
|
||||
{
|
||||
t_thread o_block;
|
||||
t_usize i;
|
||||
|
||||
i = 0;
|
||||
if (pthread_create(&o_block, NULL, &ft_watch_dogs, prog->philos))
|
||||
ft_destroy_exit("Allocation of watch_dogs failed\n", \
|
||||
ERROR, prog, forks);
|
||||
while (i < prog->philos[0].nb_philo)
|
||||
{
|
||||
if (pthread_create(&prog->philos[i].thread, NULL, &ft_routine, \
|
||||
&prog->philos[i]))
|
||||
ft_destroy_exit("Allocation of one philo thread failed !\n", \
|
||||
ERROR, prog, forks);
|
||||
i++;
|
||||
}
|
||||
while (--i > 0)
|
||||
pthread_join(prog->philos[i].thread, NULL);
|
||||
pthread_join(o_block, NULL);
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
t_usize ft_time(void)
|
||||
{
|
||||
struct timeval time;
|
||||
|
||||
if (gettimeofday(&time, NULL) == -1)
|
||||
ft_exit("Error of during ft_time !\n", 1);
|
||||
return (time.tv_sec * 1000 + time.tv_usec * 0.001);
|
||||
}
|
||||
|
||||
t_i32 main(t_i32 argc, t_str *argv)
|
||||
{
|
||||
t_philo philo[MAXSUPPORT];
|
||||
|
|
@ -19,6 +67,8 @@ t_i32 main(t_i32 argc, t_str *argv)
|
|||
|
||||
if (argc != 6 && argc != 5)
|
||||
ft_exit(ARGS, 1);
|
||||
if (ft_atou_return(argv[1]) > MAXSUPPORT)
|
||||
ft_exit("Please update the max support !\n", 1);
|
||||
if (ft_init(argc, argv, &prog, philo))
|
||||
ft_exit("Issues during initialisation\n", ERROR);
|
||||
return (0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue