This commit is contained in:
Raphael 2024-07-18 18:43:38 +02:00
parent 5215c0e3f4
commit d948c639ec
3 changed files with 14 additions and 8 deletions

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/10 00:23:09 by rparodi #+# #+# */
/* Updated: 2024/07/07 20:00:00 by rparodi ### ########.fr */
/* Updated: 2024/07/18 18:42:02 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,6 +14,10 @@
void ft_logs(t_str msg, t_philo *philo)
{
pthread_mutex_lock(philo->dead_lock);
if (philo->dead_check == true)
return ((void) pthread_mutex_unlock(philo->dead_lock));
pthread_mutex_unlock(philo->dead_lock);
pthread_mutex_lock(philo->print_lock);
const t_usize time = ft_time() - philo->start_time;
if (msg != NULL)
@ -34,17 +38,17 @@ t_error ft_start_eating(t_philo *philo)
{
if (philo->id % 2 == 0)
{
pthread_mutex_lock(philo->l_fork);
ft_logs("has taken a fork\n", philo);
pthread_mutex_lock(philo->r_fork);
ft_logs("has taken a fork\n", philo);
pthread_mutex_lock(philo->l_fork);
ft_logs("has taken a fork\n", philo);
}
else
{
pthread_mutex_lock(philo->r_fork);
ft_logs("has taken a fork\n", philo);
pthread_mutex_lock(philo->l_fork);
ft_logs("has taken a fork\n", philo);
pthread_mutex_lock(philo->r_fork);
ft_logs("has taken a fork\n", philo);
}
return (ft_ending_eating(philo));
}