Documentation for pulsar 0.7.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:
Override pulsar.Application.worker_info() to provide information about the philosopher.
The philosopher performs one of these two actions:
The philosopher has less than two forks. Check if forks are available.
The philosopher has just eaten and is ready to release both forks. This method release them, one by one, by sending the put_down action to the monitor.