In computer science, the dining philosophers problem is an exemple problem often used in concurrent algorithm design to illustrate symchronization issues and techniques for resolving them.
- [Overview].(#Overview)
- Advancing tests
Philosophers dine together at the same table. Each philosopher has his own plate at the table. There is a fork between each plate. The dish served is a kind of spaghetti which has to be eaten with two forks. Each philosopher can only alternately eat, sleep and think. Moreover, a philosopher can only eat his spaghetti when he has both a left and right fork. Thus two forks will only be available when his two nearest neighbors are sleeping or thinking, not eating. After an individual philosopher finishes eating, he will put down both forks. The problem is how to design a regimen (a concurrent algorithm) such that no philosopher will starve; i.e., each can forever continue to alternate between eating and thinking, assuming that no philosopher can know when others may want to eat, sleep or think (an issue of incomplete information).
./philo 3 610 200 80
🍝 philosophers must eat one by one without anyone dying. 🍝
./philo 2 310 200 100
💀 Philosopher who eats first must die 💀
./philo 4 350 200 50000
😴 program mustn't wait for <time_to_sleep> to end before stopping 😴
valgrind --tool=helgrind ./philo 4 450 200 200
👹 helgrind mustn't display errors 👹
valgrind --tool=helgrind ./philo 1 800 200 200
👹 helgrind mustn't display errors 👹
valgrind --tool=helgrind ./philo 3 700 200 200
👹 helgrind mustn't display errors 👹
valgrind --tool=helgrind ./philo 2 450 200 200 7
👹 helgrind mustn't display errors 👹
- 200 philosophers
./philo 200 410 200 200
🍝 philosophers must eat one by one without anyone dying. 🍝
- 1000 philosophers
./philo 1000 450 200 200
🍝 philosophers must eat one by one without anyone dying. 🍝
- 199 philosophers
./philo 199 620 200 100
🍝 philosophers must eat one by one without anyone dying. 🍝
- Try whis helgrind
valgrind --tool=helgrind ./philo 4 410 200 200
🍝 philosophers must eat one by one without anyone dying. 🍝