Documentation for pulsar 0.9.2. For development docs, go here.
The code for this example is located in the examples.philosophers.manage
module.
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.
A fork f
is placed between each pair of adjacent philosophers P
:
P P
O f O
f f
P O O P
f f
O
P
Each philosopher P
must alternately think and eat from his bowl O
.
Eating is not limited by the amount of spaghetti left: assume an infinite
supply.
However, a philosopher can only eat while holding both the fork f
to
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:
To run the example, type:
pulsar manage.py
examples.philosophers.manage.
DiningPhilosophers
(callable=None, load_config=True, **params)[source]¶worker_info
(philosopher, info=None)[source]¶Override worker_info()
to provide
information about the philosopher.
take_action
(philosopher)[source]¶The philosopher
performs one of these two actions:
release_forks()
.pickup_fork()
, if he has less than 2 forks.