/* ************************************************************************** */ /* */ /* ::: o_ :::::: ::: */ /* philo_routine.c :+: / :+::+: :+: */ /* +:+ > +:++:+ +:+ */ /* By: whaffman +#+ +:+ +#++#++:++#++ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */ /* Created: 2025/01/20 14:26:49 by whaffman #+#+# #+#+# #+# #+# | */ /* Updated: 2025/01/27 14:14:02 by whaffman ### ### ### ### / \ */ /* */ /* ************************************************************************** */ #include "philo.h" void *philo_routine(void *arg) { t_philo *philo; philo = (t_philo *)arg; synchronize_philos(philo); while (!philo->death && !get_finished(philo->rules)) { if (!philo_eat(philo)) break ; if (!philo_sleep(philo, philo->rules->time_to_eat)) break ; pthread_mutex_unlock(philo->l_fork); pthread_mutex_unlock(philo->r_fork); if (!philo->death && !get_finished(philo->rules)) print_status(philo, "is sleeping"); if (!philo_sleep(philo, philo->rules->time_to_sleep)) break ; if(!philo->death && !get_finished(philo->rules)) print_status(philo, "is thinking"); if (!philo_sleep(philo, (philo->rules->time_to_die - philo->rules->time_to_eat - philo->rules->time_to_sleep) / 3)) break ; } return (NULL); }