The code for this example is located in the
The dining philosophers problem is an example problem often used in concurrent algorithm design to illustrate synchronisation issues and techniques for resolving them.
Five silent philosophers sit at a round table with each a bowl of spaghetti.
f is placed between each pair of adjacent philosophers
P P O f O f f P O O P f f O P
P must alternately think and eat from his bowl
Eating is not limited by the amount of spaghetti left: assume an infinite
However, a philosopher can only eat while holding both the fork
the left and the fork to the right.
Each philosopher can pick up an adjacent fork, when available, and put it down,
when holding it. These are separate actions: forks must be picked up and put
down one by one.
This implementation will just work. No starvation or dead-lock.
There are two parameters:
- Average eating period, the higher the more time is spend eating.
- Average waiting period, the higher the more frequent philosophers get a chance to eat.
To run the example, type:
DiningPhilosophers(callable=None, load_config=True, **params)¶
The philosopher has fewer than two forks.
Check if forks are available.
philosopherhas just eaten and is ready to release both forks.
This method releases them, one by one, by sending the
put_downaction to the monitor.
philosopherperforms one of these two actions: