Compare commits
2 Commits
dd686a4f85
...
1ca5e59f8d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ca5e59f8d | ||
|
|
a197fdc79c |
44
.gitignore
vendored
44
.gitignore
vendored
@ -4,52 +4,10 @@
|
|||||||
|
|
||||||
# Object files
|
# Object files
|
||||||
*.o
|
*.o
|
||||||
*.ko
|
|
||||||
*.obj
|
|
||||||
*.elf
|
|
||||||
|
|
||||||
# Linker output
|
|
||||||
*.ilk
|
|
||||||
*.map
|
|
||||||
*.exp
|
|
||||||
|
|
||||||
# Precompiled Headers
|
|
||||||
*.gch
|
|
||||||
*.pch
|
|
||||||
|
|
||||||
# Libraries
|
# Libraries
|
||||||
*.lib
|
*.lib
|
||||||
*.a
|
*.a
|
||||||
*.la
|
|
||||||
*.lo
|
|
||||||
|
|
||||||
# Shared objects (inc. Windows DLLs)
|
|
||||||
*.dll
|
|
||||||
*.so
|
|
||||||
*.so.*
|
|
||||||
*.dylib
|
|
||||||
|
|
||||||
# Executables
|
|
||||||
*.exe
|
|
||||||
*.out
|
|
||||||
*.app
|
|
||||||
*.i*86
|
|
||||||
*.x86_64
|
|
||||||
*.hex
|
|
||||||
|
|
||||||
# Debug files
|
|
||||||
*.dSYM/
|
|
||||||
*.su
|
|
||||||
*.idb
|
|
||||||
*.pdb
|
|
||||||
|
|
||||||
# Kernel Module Compile Results
|
|
||||||
*.mod*
|
|
||||||
*.cmd
|
|
||||||
.tmp_versions/
|
|
||||||
modules.order
|
|
||||||
Module.symvers
|
|
||||||
Mkfile.old
|
|
||||||
dkms.conf
|
|
||||||
philo
|
philo
|
||||||
|
!philo/
|
||||||
|
|||||||
@ -57,8 +57,10 @@ typedef struct s_philo
|
|||||||
int death;
|
int death;
|
||||||
pthread_mutex_t *death_lock;
|
pthread_mutex_t *death_lock;
|
||||||
int last_meal;
|
int last_meal;
|
||||||
|
pthread_mutex_t *last_meal_lock;
|
||||||
t_rules *rules;
|
t_rules *rules;
|
||||||
int n_eat;
|
int n_eat;
|
||||||
|
pthread_mutex_t *n_eat_lock;
|
||||||
} t_philo;
|
} t_philo;
|
||||||
|
|
||||||
// memset, printf, malloc, free, write,
|
// memset, printf, malloc, free, write,
|
||||||
|
|||||||
43
philo/src/check_philos.c
Normal file
43
philo/src/check_philos.c
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: o_ :::::: ::: */
|
||||||
|
/* check_philos.c :+: / :+::+: :+: */
|
||||||
|
/* +:+ > +:++:+ +:+ */
|
||||||
|
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||||
|
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||||
|
/* Created: 2025/01/27 14:13:50 by whaffman #+#+# #+#+# #+# #+# | */
|
||||||
|
/* Updated: 2025/01/27 14:13:51 by whaffman ### ### ### ### / \ */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "philo.h"
|
||||||
|
|
||||||
|
int check_philos(t_rules *rules)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int min_n_eat;
|
||||||
|
|
||||||
|
min_n_eat = INT_MAX;
|
||||||
|
i = 0;
|
||||||
|
while (i < rules->n_philos)
|
||||||
|
{
|
||||||
|
pthread_mutex_lock(rules->philos[i].n_eat_lock);
|
||||||
|
min_n_eat = ft_min(rules->philos[i].n_eat, min_n_eat);
|
||||||
|
pthread_mutex_unlock(rules->philos[i].n_eat_lock);
|
||||||
|
pthread_mutex_lock(rules->philos[i].last_meal_lock);
|
||||||
|
if (get_time() - rules->philos[i].last_meal >= rules->time_to_die)
|
||||||
|
{
|
||||||
|
philo_die(&rules->philos[i]);
|
||||||
|
set_finished(rules);
|
||||||
|
return (FAILURE);
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(rules->philos[i].last_meal_lock);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (min_n_eat >= rules->n_must_eat)
|
||||||
|
{
|
||||||
|
set_finished(rules);
|
||||||
|
return (FAILURE);
|
||||||
|
}
|
||||||
|
return (SUCCESS);
|
||||||
|
}
|
||||||
@ -12,6 +12,22 @@
|
|||||||
|
|
||||||
#include "philo.h"
|
#include "philo.h"
|
||||||
|
|
||||||
|
int create_philo_mutexes(t_philo *philo)
|
||||||
|
{
|
||||||
|
philo->death_lock = malloc(sizeof(pthread_mutex_t));
|
||||||
|
philo->last_meal_lock = malloc(sizeof(pthread_mutex_t));
|
||||||
|
philo->n_eat_lock = malloc(sizeof(pthread_mutex_t));
|
||||||
|
if (!philo->death_lock || !philo->last_meal_lock || !philo->n_eat_lock)
|
||||||
|
return (FAILURE);
|
||||||
|
if (pthread_mutex_init(philo->death_lock, NULL))
|
||||||
|
return (FAILURE);
|
||||||
|
if (pthread_mutex_init(philo->last_meal_lock, NULL))
|
||||||
|
return (FAILURE);
|
||||||
|
if (pthread_mutex_init(philo->n_eat_lock, NULL))
|
||||||
|
return (FAILURE);
|
||||||
|
return (SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
int create_mutexes(t_rules *rules)
|
int create_mutexes(t_rules *rules)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -25,6 +41,8 @@ int create_mutexes(t_rules *rules)
|
|||||||
{
|
{
|
||||||
if (pthread_mutex_init(&rules->forks[i], NULL))
|
if (pthread_mutex_init(&rules->forks[i], NULL))
|
||||||
return (FAILURE);
|
return (FAILURE);
|
||||||
|
if (create_philo_mutexes(&rules->philos[i]) == FAILURE)
|
||||||
|
return (FAILURE);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return (SUCCESS);
|
return (SUCCESS);
|
||||||
|
|||||||
@ -24,7 +24,14 @@ int destroy_mutexes(t_rules *rules)
|
|||||||
while (i < rules->n_philos)
|
while (i < rules->n_philos)
|
||||||
{
|
{
|
||||||
if (pthread_mutex_destroy(&rules->forks[i]))
|
if (pthread_mutex_destroy(&rules->forks[i]))
|
||||||
return (FAILURE);
|
return (printf("1"), FAILURE);
|
||||||
|
if (pthread_mutex_destroy(rules->philos[i].death_lock))
|
||||||
|
return (printf("2"), FAILURE);
|
||||||
|
// pthread_mutex_lock(rules->philos[i].last_meal_lock);
|
||||||
|
if (pthread_mutex_destroy(rules->philos[i].last_meal_lock))
|
||||||
|
return (printf("3: %d\n", i), perror("Error"), FAILURE);
|
||||||
|
if (pthread_mutex_destroy(rules->philos[i].n_eat_lock))
|
||||||
|
return (printf("4"), FAILURE);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return (SUCCESS);
|
return (SUCCESS);
|
||||||
|
|||||||
@ -19,6 +19,9 @@ void free_philos(t_rules *rules)
|
|||||||
while (i < rules->n_philos)
|
while (i < rules->n_philos)
|
||||||
{
|
{
|
||||||
free(rules->philos[i].pid);
|
free(rules->philos[i].pid);
|
||||||
|
free(rules->philos[i].death_lock);
|
||||||
|
free(rules->philos[i].last_meal_lock);
|
||||||
|
free(rules->philos[i].n_eat_lock);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
free(rules->monitor);
|
free(rules->monitor);
|
||||||
|
|||||||
18
philo/src/ft_min.c
Normal file
18
philo/src/ft_min.c
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: o_ :::::: ::: */
|
||||||
|
/* ft_min.c :+: / :+::+: :+: */
|
||||||
|
/* +:+ > +:++:+ +:+ */
|
||||||
|
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||||
|
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||||
|
/* Created: 2025/01/27 14:13:55 by whaffman #+#+# #+#+# #+# #+# | */
|
||||||
|
/* Updated: 2025/01/27 14:13:55 by whaffman ### ### ### ### / \ */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
int ft_min(int a, int b)
|
||||||
|
{
|
||||||
|
if (a < b)
|
||||||
|
return (a);
|
||||||
|
return (b);
|
||||||
|
}
|
||||||
23
philo/src/get_death.c
Normal file
23
philo/src/get_death.c
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: o_ :::::: ::: */
|
||||||
|
/* get_death.c :+: / :+::+: :+: */
|
||||||
|
/* +:+ > +:++:+ +:+ */
|
||||||
|
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||||
|
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||||
|
/* Created: 2025/01/27 14:13:56 by whaffman #+#+# #+#+# #+# #+# | */
|
||||||
|
/* Updated: 2025/01/27 14:13:56 by whaffman ### ### ### ### / \ */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "philo.h"
|
||||||
|
|
||||||
|
int get_death(t_philo *philo)
|
||||||
|
{
|
||||||
|
int death;
|
||||||
|
|
||||||
|
pthread_mutex_lock(philo->death_lock);
|
||||||
|
death = philo->death;
|
||||||
|
pthread_mutex_unlock(philo->death_lock);
|
||||||
|
return (death);
|
||||||
|
}
|
||||||
23
philo/src/get_finished.c
Normal file
23
philo/src/get_finished.c
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: o_ :::::: ::: */
|
||||||
|
/* get_finished.c :+: / :+::+: :+: */
|
||||||
|
/* +:+ > +:++:+ +:+ */
|
||||||
|
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||||
|
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||||
|
/* Created: 2025/01/27 14:13:56 by whaffman #+#+# #+#+# #+# #+# | */
|
||||||
|
/* Updated: 2025/01/27 14:13:56 by whaffman ### ### ### ### / \ */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "philo.h"
|
||||||
|
|
||||||
|
int get_finished(t_rules *rules)
|
||||||
|
{
|
||||||
|
int finished;
|
||||||
|
|
||||||
|
pthread_mutex_lock(rules->finished_lock);
|
||||||
|
finished = rules->finished;
|
||||||
|
pthread_mutex_unlock(rules->finished_lock);
|
||||||
|
return (finished);
|
||||||
|
}
|
||||||
@ -18,10 +18,10 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (FAILURE == parse_arguments(argc, argv, &rules))
|
if (FAILURE == parse_arguments(argc, argv, &rules))
|
||||||
return (printf(ERROR_USAGE), EXIT_FAILURE);
|
return (printf(ERROR_USAGE), EXIT_FAILURE);
|
||||||
if (FAILURE == create_mutexes(&rules))
|
|
||||||
return (printf(ERROR_MUTEX), EXIT_FAILURE);
|
|
||||||
if (FAILURE == create_philos(&rules))
|
if (FAILURE == create_philos(&rules))
|
||||||
return (printf(ERROR_MALLOC), EXIT_FAILURE);
|
return (printf(ERROR_MALLOC), EXIT_FAILURE);
|
||||||
|
if (FAILURE == create_mutexes(&rules))
|
||||||
|
return (printf(ERROR_MUTEX), EXIT_FAILURE);
|
||||||
rules.start_time = get_time() + START_DELAY;
|
rules.start_time = get_time() + START_DELAY;
|
||||||
pthread_mutex_lock(rules.finished_lock);
|
pthread_mutex_lock(rules.finished_lock);
|
||||||
if (FAILURE == create_threads(&rules))
|
if (FAILURE == create_threads(&rules))
|
||||||
|
|||||||
31
philo/src/monitor_routine.c
Normal file
31
philo/src/monitor_routine.c
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: o_ :::::: ::: */
|
||||||
|
/* monitor_routine.c :+: / :+::+: :+: */
|
||||||
|
/* +:+ > +:++:+ +:+ */
|
||||||
|
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||||
|
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||||
|
/* Created: 2025/01/27 14:13:59 by whaffman #+#+# #+#+# #+# #+# | */
|
||||||
|
/* Updated: 2025/01/27 14:13:59 by whaffman ### ### ### ### / \ */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "philo.h"
|
||||||
|
|
||||||
|
|
||||||
|
void *monitor_routine(void *arg)
|
||||||
|
{
|
||||||
|
t_rules *rules;
|
||||||
|
|
||||||
|
rules = (t_rules *)arg;
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (!check_philos(rules))
|
||||||
|
{
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
usleep(500);
|
||||||
|
}
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
24
philo/src/philo_die.c
Normal file
24
philo/src/philo_die.c
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: o_ :::::: ::: */
|
||||||
|
/* philo_die.c :+: / :+::+: :+: */
|
||||||
|
/* +:+ > +:++:+ +:+ */
|
||||||
|
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||||
|
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||||
|
/* Created: 2025/01/27 14:14:00 by whaffman #+#+# #+#+# #+# #+# | */
|
||||||
|
/* Updated: 2025/01/27 14:14:00 by whaffman ### ### ### ### / \ */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "philo.h"
|
||||||
|
|
||||||
|
void philo_die(t_philo *philo)
|
||||||
|
{
|
||||||
|
print_status(philo, "died");
|
||||||
|
pthread_mutex_lock(philo->death_lock);
|
||||||
|
philo->death = 1;
|
||||||
|
pthread_mutex_unlock(philo->death_lock);
|
||||||
|
set_finished(philo->rules);
|
||||||
|
pthread_mutex_unlock(philo->l_fork);
|
||||||
|
pthread_mutex_unlock(philo->r_fork);
|
||||||
|
}
|
||||||
39
philo/src/philo_eat.c
Normal file
39
philo/src/philo_eat.c
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: o_ :::::: ::: */
|
||||||
|
/* philo_eat.c :+: / :+::+: :+: */
|
||||||
|
/* +:+ > +:++:+ +:+ */
|
||||||
|
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||||
|
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||||
|
/* Created: 2025/01/27 14:14:01 by whaffman #+#+# #+#+# #+# #+# | */
|
||||||
|
/* Updated: 2025/01/27 14:14:01 by whaffman ### ### ### ### / \ */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "philo.h"
|
||||||
|
|
||||||
|
int philo_eat(t_philo *philo)
|
||||||
|
{
|
||||||
|
if (philo->id % 2 == 1)
|
||||||
|
{
|
||||||
|
pthread_mutex_lock(philo->r_fork);
|
||||||
|
print_status(philo, "has taken a fork");
|
||||||
|
}
|
||||||
|
pthread_mutex_lock(philo->l_fork);
|
||||||
|
print_status(philo, "has taken a fork");
|
||||||
|
if (philo->id % 2 != 1)
|
||||||
|
{
|
||||||
|
pthread_mutex_lock(philo->r_fork);
|
||||||
|
print_status(philo, "has taken a fork");
|
||||||
|
}
|
||||||
|
if (get_finished(philo->rules))
|
||||||
|
return (FAILURE);
|
||||||
|
print_status(philo, "is eating");
|
||||||
|
pthread_mutex_lock(philo->last_meal_lock);
|
||||||
|
philo->last_meal = get_time();
|
||||||
|
pthread_mutex_unlock(philo->last_meal_lock);
|
||||||
|
pthread_mutex_lock(philo->n_eat_lock);
|
||||||
|
philo->n_eat++;
|
||||||
|
pthread_mutex_unlock(philo->n_eat_lock);
|
||||||
|
return (SUCCESS);
|
||||||
|
}
|
||||||
26
philo/src/philo_sleep.c
Normal file
26
philo/src/philo_sleep.c
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: o_ :::::: ::: */
|
||||||
|
/* philo_sleep.c :+: / :+::+: :+: */
|
||||||
|
/* +:+ > +:++:+ +:+ */
|
||||||
|
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||||
|
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||||
|
/* Created: 2025/01/27 14:14:02 by whaffman #+#+# #+#+# #+# #+# | */
|
||||||
|
/* Updated: 2025/01/27 14:14:02 by whaffman ### ### ### ### / \ */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "philo.h"
|
||||||
|
|
||||||
|
int philo_sleep(t_philo *philo, int time)
|
||||||
|
{
|
||||||
|
const int start = get_time();
|
||||||
|
|
||||||
|
while (get_time() - start < time)
|
||||||
|
{
|
||||||
|
if (philo->death)
|
||||||
|
return (FAILURE);
|
||||||
|
usleep(50);
|
||||||
|
}
|
||||||
|
return (SUCCESS);
|
||||||
|
}
|
||||||
21
philo/src/set_death.c
Normal file
21
philo/src/set_death.c
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: o_ :::::: ::: */
|
||||||
|
/* set_death.c :+: / :+::+: :+: */
|
||||||
|
/* +:+ > +:++:+ +:+ */
|
||||||
|
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||||
|
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||||
|
/* Created: 2025/01/27 14:14:03 by whaffman #+#+# #+#+# #+# #+# | */
|
||||||
|
/* Updated: 2025/01/27 14:14:03 by whaffman ### ### ### ### / \ */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "philo.h"
|
||||||
|
|
||||||
|
|
||||||
|
void set_death(t_philo *philo)
|
||||||
|
{
|
||||||
|
pthread_mutex_lock(philo->death_lock);
|
||||||
|
philo->death = 1;
|
||||||
|
pthread_mutex_unlock(philo->death_lock);
|
||||||
|
}
|
||||||
20
philo/src/set_finished.c
Normal file
20
philo/src/set_finished.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: o_ :::::: ::: */
|
||||||
|
/* set_finished.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 set_finished(t_rules *rules)
|
||||||
|
{
|
||||||
|
pthread_mutex_lock(rules->finished_lock);
|
||||||
|
rules->finished = 1;
|
||||||
|
pthread_mutex_unlock(rules->finished_lock);
|
||||||
|
}
|
||||||
27
philo/src/synchronize_philos.c
Normal file
27
philo/src/synchronize_philos.c
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user