Skip to content

Commit

Permalink
Merge pull request #93 from biralavor/92-fixing-zombie-mode
Browse files Browse the repository at this point in the history
fixing zombie mode
  • Loading branch information
biralavor authored Nov 5, 2024
2 parents 5223041 + f5ca5d2 commit b1fb454
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
8 changes: 4 additions & 4 deletions philo/src/11.printer_with_mutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/30 11:12:00 by umeneses #+# #+# */
/* Updated: 2024/11/04 19:00:53 by umeneses ### ########.fr */
/* Updated: 2024/11/05 11:00:04 by umeneses ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -20,11 +20,11 @@ void printer_manager(t_philo_status status, t_philo *philo, int debug)
if (philo->full)
return ;
safe_mutex_handler(&philo->table->printer_mtx, LOCK);
if (debug == 1)
if (debug == 1 && !this_is_the_end_of_dinner(philo->table))
printer_with_mutex_chopsticks(status, philo, elapsed);
else if (debug == 2)
else if (debug == 2 && !this_is_the_end_of_dinner(philo->table))
printer_with_mutex_debug(status, philo, elapsed);
else
else if (!this_is_the_end_of_dinner(philo->table))
printer_with_mutex_classic(status, philo, elapsed);
safe_mutex_handler(&philo->table->printer_mtx, UNLOCK);
}
Expand Down
6 changes: 3 additions & 3 deletions philo/src/12.dinner_routines.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/30 16:19:23 by umeneses #+# #+# */
/* Updated: 2024/11/05 10:49:33 by umeneses ### ########.fr */
/* Updated: 2024/11/05 11:12:50 by umeneses ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -41,8 +41,8 @@ void let_philo_think_routine(t_philo *philo, bool before_spinlock)
return ;
else
{
think_time = (philo->table->set.time_to_eat
* 2) - philo->table->set.time_to_sleep;
think_time = (philo->table->set.time_to_eat * 2)
- philo->table->set.time_to_sleep;
if (think_time < 0)
think_time = 0;
precise_usleep(think_time * 0.5, philo->table);
Expand Down
13 changes: 7 additions & 6 deletions philo/src/13.monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/04 18:57:56 by umeneses #+# #+# */
/* Updated: 2024/11/04 18:58:26 by umeneses ### ########.fr */
/* Updated: 2024/11/05 10:59:03 by umeneses ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -30,8 +30,8 @@ void *monitor_runner(void *data)
{
if (is_philo_dead_manager(table->philos + idx))
{
set_bool(&table->table_mtx, &table->this_is_the_end, true);
printer_manager(DEAD, table->philos + idx, DEBUG_MODE);
set_bool(&table->table_mtx, &table->this_is_the_end, true);
}
}
}
Expand All @@ -41,14 +41,15 @@ void *monitor_runner(void *data)
bool is_philo_dead_manager(t_philo *philo)
{
long time_to_die;
long elapsed;
long current;
long last_meal;

if (get_bool(&philo->philo_mtx, &philo->full))
return (false);
elapsed = ft_gettime(MILLISECOND) - get_long(&philo->philo_mtx,
&philo->time_of_last_meal);
current = ft_gettime(MILLISECOND);
last_meal = get_long(&philo->philo_mtx, &philo->time_of_last_meal);
time_to_die = philo->table->set.time_to_die / 1e3;
if (elapsed > time_to_die)
if (current - last_meal > time_to_die)
return (true);
return (false);
}

0 comments on commit b1fb454

Please sign in to comment.