possible race conflicts resolut

This commit is contained in:
hugogogo
2022-01-30 15:53:45 +01:00
parent d9142b9af6
commit 7dc4c5a84f
7 changed files with 245 additions and 11 deletions

View File

@@ -6,7 +6,7 @@
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/26 15:30:34 by hulamy #+# #+# */
/* Updated: 2022/01/27 15:01:30 by hulamy ### ########.fr */
/* Updated: 2022/01/30 15:48:11 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
@@ -24,6 +24,10 @@ static t_philo *lst_add_philo(t_params *params, t_global *global, int i)
new->p_nbr = i + 1;
if (pthread_mutex_init(&(new->m_fork), NULL) != 0)
return (NULL);
if (pthread_mutex_init(&(new->m_time), NULL) != 0)
return (NULL);
if (pthread_mutex_init(&(new->m_eat), NULL) != 0)
return (NULL);
new->t_last_meal.ts = 0;
new->t_last_meal.tu = 0;
new->eat_count = 0;
@@ -97,6 +101,10 @@ static t_global *init_global(void)
global->t_start.tu = 0;
if (pthread_mutex_init(&(global->m_print), NULL) != 0)
return (NULL);
if (pthread_mutex_init(&(global->m_init_time), NULL) != 0)
return (NULL);
if (pthread_mutex_init(&(global->m_stop), NULL) != 0)
return (NULL);
return (global);
}