Philosophers is a 42 school project that consists in creating a program that reproduce the dining philosophers problem.
Screen.Recording.2023-04-27.at.5.49.19.PM.mov
Running simulation with 5 philosophers.
./philo 5 800 200 200
Clone the repository from GitHub:
git clone https://github.com/okbrandon/philosophers.git
Compile the philo
executable:
cd philo/ && make
Compile the philo_bonus
executable:
cd philo_bonus/ && make
Run the mandatory program:
./philo <num_of_philo> <time_to_die> <time_to_eat> <time_to_sleep> [<must_eat>]
First parameter is how much philosophers you want, the second one is after how many millis they should die after their last meal, the third one is the time they take to eat in millis, same for the forth parameter. The last one is optional and represent how many times each philosopher should eat at least.
Run the bonus program:
./philo_bonus <num_of_philo> <time_to_die> <time_to_eat> <time_to_sleep> [<must_eat>]
Same as above.
Valid simulation:
$> ./philo 5 800 200 200
0 1 has taken a fork
0 3 has taken a fork
0 3 has taken a fork
0 3 is eating
0 1 has taken a fork
0 1 is eating
0 5 has taken a fork
200 4 has taken a fork
200 3 is sleeping
200 5 has taken a fork
200 5 is eating
200 1 is sleeping
200 2 has taken a fork
200 2 has taken a fork
200 2 is eating
[...]
Invalid simulation:
$> ./philo 5 400 200 200
0 1 has taken a fork
0 1 has taken a fork
0 1 is eating
0 3 has taken a fork
0 3 has taken a fork
0 5 has taken a fork
0 3 is eating
200 3 is sleeping
200 5 has taken a fork
200 5 is eating
200 1 is sleeping
200 4 has taken a fork
200 2 has taken a fork
200 2 has taken a fork
200 2 is eating
400 3 is thinking
400 3 has taken a fork
400 2 is sleeping
400 5 is sleeping
400 1 is thinking
400 1 has taken a fork
400 4 has taken a fork
400 4 is eating
400 1 died
The bonus program has the same output as the mandatory one. The only difference is that the mandatory uses mutexes and the bonus one semaphores.
bsoubaig β bsoubaig@student.42nice.fr