Skip to content

Commit

Permalink
building sleeping routine
Browse files Browse the repository at this point in the history
  • Loading branch information
biralavor committed Oct 30, 2024
1 parent 0736803 commit ac500fc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion philo/headers/philo.h
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/17 16:04:11 by umeneses #+# #+# */
/* Updated: 2024/10/30 16:40:10 by umeneses ### ########.fr */
/* Updated: 2024/10/30 16:40:57 by umeneses ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -149,6 +149,7 @@ void printer_with_mutex_debug(t_philo_status status, t_philo *philo, bool debbug
/* dinner routines functions */
void let_philo_eat_routine(t_philo *philo);
void let_philo_think_routine(t_philo *philo);
void let_philo_sleep_routine(t_philo *philo);

/* LIBFT utility functions */
int ft_strlen(const char *str);
Expand Down
6 changes: 3 additions & 3 deletions philo/src/08.dinner_manager.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/29 10:01:45 by umeneses #+# #+# */
/* Updated: 2024/10/30 16:29:27 by umeneses ### ########.fr */
/* Updated: 2024/10/30 16:39:45 by umeneses ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -58,7 +58,7 @@ void dinner_startup_runner(t_table *table)
if (table->philo->full) // TODO: thread safe
break ;
let_philo_eat_routine(table->philo);
let_think_routine(table->philo);
// let_sleep_routine(table->philo); // TODO
let_philo_think_routine(table->philo);
let_philo_sleep_routine(table->philo);
}
}
7 changes: 6 additions & 1 deletion 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/10/30 16:40:25 by umeneses ### ########.fr */
/* Updated: 2024/10/30 16:41:36 by umeneses ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -37,3 +37,8 @@ void let_philo_think_routine(t_philo *philo)
// safe_mutex_handler(philo->philo_mtx, UNLOCK);
}

void let_philo_sleep_routine(t_philo *philo)
{
printer_with_mutex(SLEEPING, philo, false);
precise_usleep(philo->table->set->time_to_sleep, philo->table);
}

0 comments on commit ac500fc

Please sign in to comment.