Dining Philosophers Problem

Q1. Explain Dining Philosophers Problem.

Ans. The dining philosophers problem is considered a classic synchronization problem because it is an example of a large class of concurrency – control problems. It is a simple representation of the need to allocate several resources among several processes in a deadlock free and starvation free manner.

Dining philosopher

Figure: The situation of the dining philosophers

It has no deadlock. Starvation is to protect the five statements following the call to think by a binary semaphore before starting to acquire forks; philosopher would do a down on mutex. After replacing the forks she would do a up on mutex.

It has a performance bug, only one philosopher can be eating at any instant with five forks available, we should be able to allow two philosophers to eat at the same time.

Solution allows the maximum number of arbitrary philosophers. It uses an array, state to keep track of whether philosophers is eating, thinking or hungry. A philosopher may move only into eating state, if neither neighbor is eating. Philosopher i’s neighbors are defined by left and right. The program uses an array of semaphore 1, per philosopher. So hungry philosopher can block, if the needed forks are busy.

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: