33 lines
1.4 KiB
C
33 lines
1.4 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: o_ :::::: ::: */
|
|
/* synchronize_philos.c :+: / :+::+: :+: */
|
|
/* +:+ > +:++:+ +:+ */
|
|
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
|
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
|
/* Created: 2025/01/27 14:14:04 by whaffman #+#+# #+#+# #+# #+# | */
|
|
/* Updated: 2025/01/27 14:14:04 by whaffman ### ### ### ### / \ */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "philo.h"
|
|
|
|
void synchronize_philos(t_philo *philo)
|
|
{
|
|
pthread_mutex_lock(philo->rules->finished_lock);
|
|
pthread_mutex_unlock(philo->rules->finished_lock);
|
|
pthread_mutex_lock(philo->last_meal_lock);
|
|
philo->last_meal = get_time();
|
|
pthread_mutex_unlock(philo->last_meal_lock);
|
|
if (philo->id % 2 == 0)
|
|
{
|
|
print_status(philo, "is thinking");
|
|
usleep(philo->rules->time_to_eat * 10);
|
|
}
|
|
else if (philo->id == philo->rules->n_philos && philo->rules->n_philos > 1)
|
|
{
|
|
print_status(philo, "is thinking");
|
|
usleep(philo->rules->time_to_eat * 10);
|
|
}
|
|
}
|