Joshy Kasahara's profile

Solving the Dining Philosophers Problem in Your Palm

Five silent philosophers sit at a table around a bowl of spaghetti. A fork is placed between each pair of adjacent philosophers. (An alternative problem formulation uses rice and chopsticks instead of spaghetti and forks.)
Each philosopher must alternately think and eat. However, a philosopher can only eat spaghetti when he has both left and right forks. Each fork can be held by only one philosopher and so a philosopher can use the fork only if it's not being used by another philosopher. After he finishes eating, he needs to put down both forks so they become available to others. A philosopher can grab the fork on his right or the one on his left as they become available, but can't start eating before getting both of them.
 
Eating is not limited by the amount of spaghetti left: assume an infinite supply.
 
The problem is how to design a discipline of behavior (a concurrent algorithm) such that each philosopher won't starve; i.e., can forever continue to alternate between eating and thinking assuming that any philosopher cannot know when others may want to eat or think. — Wikipedia, Dining Philosophers Problem
What's happening?
- The dining philosophers problem is useful for modeling processes that are competing for exclusive access to a limited number of resources, such as I/O devices.
- Consider five philosophers who spend their lives thinking and eating.
- The philosophers share a circular table surrounded by five chairs, each belonging to one philosopher. In the center of the table is food (resource), and the table is laid with five single forks.
- When a philosopher thinks, he does not interact with his colleagues.
- From time to time, a philosopher gets hungry and tries to pick up the two forks that are closest to him (the forks that are between him and his left and right neighbors).
- A philosopher may pick up only one chopstick at a time. Obviously, he cannot pick up a chopstick that is already in the hand of a neighbor.
- When he is finished eating, he puts down both of his forks and starts thinking again.
 
Solving the Dining Philosophers Problem in Your Palm
Published:

Solving the Dining Philosophers Problem in Your Palm

In computer science, the dining philosophers problem is an example problem often used in concurrent algorithm design to illustrate synchronizatio Read More

Published: