「🔨」 fix: fixed error in helgrind
This commit is contained in:
10
philo/eat.c
10
philo/eat.c
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/08/08 17:29:51 by adjoly #+# #+# */
|
/* Created: 2024/08/08 17:29:51 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/08/12 20:50:55 by adjoly ### ########.fr */
|
/* Updated: 2024/08/12 21:04:57 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -23,19 +23,21 @@ void take_fork(t_fork *fork, int id)
|
|||||||
bool philo_eat(t_philo *philo)
|
bool philo_eat(t_philo *philo)
|
||||||
{
|
{
|
||||||
philo->state = FORK_TAKEN;
|
philo->state = FORK_TAKEN;
|
||||||
take_fork(&philo->fork, philo->id);
|
|
||||||
if (get_death(philo, RETURN))
|
if (get_death(philo, RETURN))
|
||||||
return (true);
|
return (true);
|
||||||
|
take_fork(&philo->fork, philo->id);
|
||||||
log_philo(philo);
|
log_philo(philo);
|
||||||
if (&(philo->fork.left) == philo->fork.right)
|
if (&(philo->fork.left) == philo->fork.right)
|
||||||
return (print_death(philo));
|
return (print_death(philo));
|
||||||
|
if (get_death(philo, RETURN))
|
||||||
|
return (true);
|
||||||
take_fork(&philo->fork, philo->id + 1);
|
take_fork(&philo->fork, philo->id + 1);
|
||||||
// if (get_death(philo, RETURN))
|
|
||||||
// return (true);
|
|
||||||
log_philo(philo);
|
log_philo(philo);
|
||||||
philo->state = EAT;
|
philo->state = EAT;
|
||||||
log_philo(philo);
|
log_philo(philo);
|
||||||
|
pthread_mutex_lock(philo->check);
|
||||||
gettimeofday(&philo->eat, NULL);
|
gettimeofday(&philo->eat, NULL);
|
||||||
|
pthread_mutex_unlock(philo->check);
|
||||||
if (sleep_phil(philo) == true)
|
if (sleep_phil(philo) == true)
|
||||||
return (true);
|
return (true);
|
||||||
pthread_mutex_unlock(&philo->fork.left);
|
pthread_mutex_unlock(&philo->fork.left);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/08/12 12:13:35 by adjoly #+# #+# */
|
/* Created: 2024/08/12 12:13:35 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/08/12 20:50:17 by adjoly ### ########.fr */
|
/* Updated: 2024/08/12 21:00:27 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -22,13 +22,17 @@ bool philo_check(t_philo *philo, t_pdata data)
|
|||||||
eaten = 0;
|
eaten = 0;
|
||||||
while (i < data.philo_nbr)
|
while (i < data.philo_nbr)
|
||||||
{
|
{
|
||||||
|
|
||||||
gettimeofday(&t1, NULL);
|
gettimeofday(&t1, NULL);
|
||||||
|
pthread_mutex_lock(philo->check);
|
||||||
if (get_time_in_ms(philo[i].eat, t1) > data.die_time)
|
if (get_time_in_ms(philo[i].eat, t1) > data.die_time)
|
||||||
{
|
{
|
||||||
|
pthread_mutex_unlock(philo->check);
|
||||||
pthread_mutex_unlock(&philo[i].fork.left);
|
pthread_mutex_unlock(&philo[i].fork.left);
|
||||||
pthread_mutex_unlock(philo[i].fork.right);
|
pthread_mutex_unlock(philo[i].fork.right);
|
||||||
return (print_death(&philo[i]));
|
return (print_death(&philo[i]));
|
||||||
}
|
}
|
||||||
|
pthread_mutex_unlock(philo->check);
|
||||||
if (philo[i].meal_left == 0)
|
if (philo[i].meal_left == 0)
|
||||||
eaten++;
|
eaten++;
|
||||||
if (get_death(philo, RETURN))
|
if (get_death(philo, RETURN))
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/22 21:24:53 by adjoly #+# #+# */
|
/* Created: 2024/07/22 21:24:53 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/08/12 20:27:14 by adjoly ### ########.fr */
|
/* Updated: 2024/08/12 21:03:47 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/23 17:15:24 by adjoly #+# #+# */
|
/* Created: 2024/07/23 17:15:24 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/08/12 20:47:05 by adjoly ### ########.fr */
|
/* Updated: 2024/08/12 21:05:12 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user