gestion cas n_eat a zero
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/01/26 15:30:28 by hulamy #+# #+# */
|
||||
/* Updated: 2022/01/26 16:29:49 by hulamy ### ########.fr */
|
||||
/* Updated: 2022/01/26 18:51:44 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -44,10 +44,8 @@ static int eat(t_philo *philo)
|
||||
update_time(philo);
|
||||
if (print_message(philo, B_YELLOW, "is eating"))
|
||||
return (ret_err_unlock(philo, 2));
|
||||
philo->eat_count++;
|
||||
if (philo->eat_count == philo->params->n_eat)
|
||||
philo->global->satiated_count++;
|
||||
action_delay(philo, philo->params->t_eat);
|
||||
philo->eat_count++;
|
||||
pthread_mutex_unlock(&(philo->next->m_fork));
|
||||
pthread_mutex_unlock(&(philo->m_fork));
|
||||
return (0);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/01/26 15:30:34 by hulamy #+# #+# */
|
||||
/* Updated: 2022/01/26 17:55:34 by hulamy ### ########.fr */
|
||||
/* Updated: 2022/01/26 18:15:42 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/01/26 15:30:49 by hulamy #+# #+# */
|
||||
/* Updated: 2022/01/26 16:29:13 by hulamy ### ########.fr */
|
||||
/* Updated: 2022/01/26 18:52:32 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -36,17 +36,31 @@ static int is_finished(t_philo *philo, struct timeval *stime)
|
||||
return (0);
|
||||
}
|
||||
|
||||
int is_satiated(t_philo *philo)
|
||||
{
|
||||
if (philo->eat_count == philo->params->n_eat)
|
||||
{
|
||||
philo->global->satiated_count++;
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void pere_fouettard(t_philo *philo)
|
||||
{
|
||||
struct timeval stime;
|
||||
int i;
|
||||
int satiated;
|
||||
|
||||
while (philo->global->stop == 0)
|
||||
{
|
||||
i = 0;
|
||||
satiated = 1;
|
||||
gettimeofday(&stime, NULL);
|
||||
while (i < philo->params->n_phi)
|
||||
{
|
||||
if (satiated == 1 && is_satiated(philo) == 0)
|
||||
satiated = 0;
|
||||
if (is_finished(philo, &stime))
|
||||
break ;
|
||||
philo = philo->next;
|
||||
|
||||
18
srcs/utils.c
18
srcs/utils.c
@@ -6,7 +6,7 @@
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/01/26 15:30:19 by hulamy #+# #+# */
|
||||
/* Updated: 2022/01/26 17:50:31 by hulamy ### ########.fr */
|
||||
/* Updated: 2022/01/26 18:04:08 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -34,7 +34,7 @@ int ft_isdigit_2d_arr(char **str)
|
||||
|
||||
size_t ft_strlen(char *str)
|
||||
{
|
||||
size_t i;
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (str[i])
|
||||
@@ -56,9 +56,9 @@ int ft_strncmp(char *s1, char *s2, size_t n)
|
||||
return (res);
|
||||
}
|
||||
|
||||
int ft_int_overflow(char *str)
|
||||
int ft_int_overflow(char *str)
|
||||
{
|
||||
size_t len;
|
||||
size_t len;
|
||||
char *int_xtrem;
|
||||
|
||||
int_xtrem = "2147483647";
|
||||
@@ -67,11 +67,11 @@ int ft_int_overflow(char *str)
|
||||
if (str[0] == '+' || str[0] == '-')
|
||||
str++;
|
||||
len = ft_strlen(str);
|
||||
if (len < 10)
|
||||
return (0);
|
||||
else if (len > 10 || ft_strncmp(str, int_xtrem, len) > 0)
|
||||
return (1);
|
||||
return (0);
|
||||
if (len < 10)
|
||||
return (0);
|
||||
else if (len > 10 || ft_strncmp(str, int_xtrem, len) > 0)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int ft_atoi(const char *str)
|
||||
|
||||
Reference in New Issue
Block a user