42 Cursus - philosophers: this project is a training to multi-threads/multi-process programming.
- Status: finished
- Result: 125%
- Observations: (null)
The classic dining philosopher problem.
This problem states that N philosophers seated around a circular table with one fork between each pair of philosophers. A philosopher may eat if he can pick up the two forks adjacent to him. One fork may be picked up by any one of its adjacent followers but not both.
Each time a philosopher finish eating, they will drop drop their forks and start sleeping. Once they have finished sleeping, the will start thinking and waiting to eat.
Simulation stops when a philosopher dies.
Every philosopher needs to eat and they should never starve.
Philosophers do not speak with each other.
Philosophers do not know when another philospher is about to die.
And of course, philosophers should avoid dying.
philo: philosophers with threads and mutex.
- One fork between each pair of philosophers.
philo_bonus: philosophers with processes and semaphore.
- All the forks are in the middle of the table.
Clone the repo
git clone https://github.com/izenynn/libft.git
Go to philo
or philo_bonus
folder and run make
cd ./philo && make
cd ./philo_bonus && make
- Makefile rules:
all
,clean
,fclean
,re
).
Usage
./philo [N PHILOS] [DIE TIME] [EAT TIME] [SLEEP TIME] (OPT)[PHILO EAT N TIMES]
-
last argument is optional.
-
philo_bonus
takes the same arguments asphilo
.
Example
./philo 4 800 200 200
./philo_bonus 10 410 200 200 7