Pushing from the laptop the sources

This commit is contained in:
Raphael 2024-07-24 12:33:15 +02:00
parent c2db9acc15
commit 6f7b3a44d2
2 changed files with 11 additions and 9 deletions

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/04 11:34:04 by rparodi #+# #+# */
/* Updated: 2024/07/18 21:17:07 by rparodi ### ########.fr */
/* Updated: 2024/07/23 21:04:56 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
@ -42,11 +42,11 @@ typedef struct s_philo
t_usize t_eat;
t_usize t_death;
t_usize t_sleep;
t_i32 nb_eat;
t_usize nb_eat;
pthread_t thread;
t_i32 id;
t_i32 eating;
t_i32 eating_count;
t_usize eating_count;
t_usize t_last_eat;
t_usize start_time;
t_bool dead_check;
@ -87,7 +87,7 @@ t_error ft_ending_eating(t_philo *philo);
void ft_putchar_fd(t_i32 fd, t_str str);
void ft_logs(t_str msg, t_philo *philo);
t_error ft_atou(const char *nptr, t_usize *value);
t_error ft_init_fork(t_philo *philo, t_mutex *fork);
t_error ft_init_fork(t_mutex *fork, t_usize nb_fork);
void counting_launch(t_philo *philo, t_u8 *counter);
t_error ft_init_thread(t_program *prog, t_mutex *forks);
t_error ft_parsing_args(t_i32 argc, t_str *argv, t_philo *philo);

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/04 11:42:37 by rparodi #+# #+# */
/* Updated: 2024/07/23 20:03:47 by rparodi ### ########.fr */
/* Updated: 2024/07/23 21:07:50 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
@ -40,14 +40,15 @@ t_error ft_parsing_args(t_i32 argc, t_str *argv, t_philo *philo)
return (NO_ERROR);
}
t_error ft_init_fork(t_philo *philo, t_mutex *fork)
t_error ft_init_fork(t_mutex *fork, t_usize nb_fork)
{
t_usize i;
i = 0;
while (i < philo->nb_philo)
while (i < nb_fork)
{
pthread_mutex_init(&fork[i], NULL);
printf("\tforks[%zu]\n", i + 1);
fork[i] = (t_mutex)PTHREAD_MUTEX_INITIALIZER;
i++;
}
return (NO_ERROR);
@ -82,6 +83,7 @@ t_error ft_init_philo(t_i32 argc, t_str *argv, t_program *prog, t_mutex *forks)
prog->philos[i].r_fork = &forks[prog->philos[i].nb_philo - 1];
else
prog->philos[i].r_fork = &forks[i - 1];
printf("\tphilo[%zu]\n", i + 1);
i++;
}
if (ft_parsing_args(argc, argv, prog->philos))
@ -97,9 +99,9 @@ t_error ft_init(t_i32 argc, t_str *argv, t_program *prog, t_philo *philo)
prog->dead_lock = (t_mutex)PTHREAD_MUTEX_INITIALIZER;
prog->meal_lock = (t_mutex)PTHREAD_MUTEX_INITIALIZER;
prog->check_eating_count = (t_mutex)PTHREAD_MUTEX_INITIALIZER;
ft_init_fork(prog->philos, forks);
prog->philos = philo;
prog->dead_flag = false;
ft_init_fork(forks, ft_atou_return(argv[1]));
if (ft_init_philo(argc, argv, prog, forks))
return (ERROR);
if (philo->nb_philo != 0 && philo->nb_philo > MAXSUPPORT)