Dining Philosophers Problem
Dining Philosophers Problem
The philosophers never speak to each other, which creates a dangerous possibility
of deadlock. The deadlock could occur if every philosopher holds a left chopstick
and waits perpetually for a right chopstick (or vice versa).
this problem has attracted and challenged both theoreticians and programmers, and
a variety of different solutions have been developed, most of them using some kind
of synchronization mechanism (typically a semaphore) to control accesses to
chopsticks by hungry philosophers.
Figure 1
2. Dining Philosophers
No two philosophers can use the same fork at the same time ( mutual exclusion).
3. Dining-Philosophers Problem
• There is one chopstick between each philosopher.
• A philosopher must pick up its two nearest chopsticks in order to eat.
• A philosopher must pick up the first one chopstick, then the second one, not
both at once.
We need an algorithm for allocating these limited resources(chopsticks) among
several processes(philosophers) such that solution is free from deadlock and free
from starvation.
There exist some algorithm to solve Dining – Philosopher Problem, but they may
have deadlock situation. Also, a deadlock-free solution is not necessarily starvation-
free. Semaphores can result in deadlock due to programming errors. Monitors alone
are not sufficiency to solve this, we need monitors with condition variables.
• EATING – When the philosopher has got both the forks, i.e., he has entered
the section.
References
geeksforgeeks.org.