mise a la norme

This commit is contained in:
hugogogo
2022-01-31 10:28:26 +01:00
parent 774bdb0a4a
commit 41726f5e41
5 changed files with 39 additions and 253 deletions

View File

@@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* exec.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/31 10:23:55 by hulamy #+# #+# */
/* Updated: 2022/01/31 10:25:02 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "philo.h"
static void action_delay(t_philo *philo, int action_time)
@@ -22,6 +34,25 @@ static int ret_err_unlock(t_mtx *fork1, t_mtx *fork2)
return (1);
}
/*
Thread #3: lock order "0x54542E8 before 0x54541F8" violated
Observed (incorrect) order is: acquisition of lock at 0x54541F8
at 0x4C3603C: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
by 0x4011BC: eat (exec.c:27)
by 0x401119: philo_exec (exec.c:72)
by 0x4C38C26: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
by 0x4E4B6DA: start_thread (pthread_create.c:463)
by 0x518471E: clone (clone.S:95)
followed by a later acquisition of lock at 0x54542E8
at 0x4C3603C: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
by 0x401226: eat (exec.c:32)
by 0x401119: philo_exec (exec.c:72)
by 0x4C38C26: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
by 0x4E4B6DA: start_thread (pthread_create.c:463)
by 0x518471E: clone (clone.S:95)
*/
static int eat(t_philo *philo, t_mtx *fork1, t_mtx *fork2)
{
pthread_mutex_lock(fork1);
@@ -35,7 +66,6 @@ static int eat(t_philo *philo, t_mtx *fork1, t_mtx *fork2)
update_time(philo);
if (print_message(philo, B_YELLOW, "is eating"))
return (ret_err_unlock(fork1, fork2));
action_delay(philo, philo->params->t_eat);
pthread_mutex_lock(&(philo->m_eat));
philo->eat_count++;
@@ -46,14 +76,11 @@ static int eat(t_philo *philo, t_mtx *fork1, t_mtx *fork2)
}
/*
** fork1 = &(philo->m_fork);
** fork2 = &(philo->m_fork);
** if (philo->global->t_start.ts == 0)
** if (philo->p_nbr < philo->params->n_phi / 2)
** if (philo->p_nbr % 2 == 0)
** fork1 = &(philo->next->m_fork);
** else
** fork2 = &(philo->next->m_fork);
if (philo->p_nbr % 2 == 0)
{
fork1 = &(philo->next->m_fork);
fork2 = &(philo->m_fork);
}
*/
void *philo_exec(void *arg)
{
@@ -79,22 +106,3 @@ void *philo_exec(void *arg)
}
return (NULL);
}
/*
==22761== Thread #3: lock order "0x54542E8 before 0x54541F8" violated
==22761==
==22761== Observed (incorrect) order is: acquisition of lock at 0x54541F8
==22761== at 0x4C3603C: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==22761== by 0x4011BC: eat (exec.c:27)
==22761== by 0x401119: philo_exec (exec.c:72)
==22761== by 0x4C38C26: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==22761== by 0x4E4B6DA: start_thread (pthread_create.c:463)
==22761== by 0x518471E: clone (clone.S:95)
==22761==
==22761== followed by a later acquisition of lock at 0x54542E8
==22761== at 0x4C3603C: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==22761== by 0x401226: eat (exec.c:32)
==22761== by 0x401119: philo_exec (exec.c:72)
==22761== by 0x4C38C26: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==22761== by 0x4E4B6DA: start_thread (pthread_create.c:463)
==22761== by 0x518471E: clone (clone.S:95)
*/