0% found this document useful (0 votes)
169 views

Dining Philosophers Problem

The dining philosophers problem describes a situation where an unknown number of philosophers sit at a table with a limited number of chopsticks between them. Each philosopher must acquire the chopsticks on either side of them to eat, but they cannot acquire both at once or deadlock could occur if all philosophers wait indefinitely. Several algorithms and solutions using synchronization mechanisms like semaphores have been developed to solve this problem by preventing deadlock and ensuring no philosopher starves. Monitor-based solutions with condition variables are needed to fully solve the problem without issues.

Uploaded by

Ramadan Gadah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
169 views

Dining Philosophers Problem

The dining philosophers problem describes a situation where an unknown number of philosophers sit at a table with a limited number of chopsticks between them. Each philosopher must acquire the chopsticks on either side of them to eat, but they cannot acquire both at once or deadlock could occur if all philosophers wait indefinitely. Several algorithms and solutions using synchronization mechanisms like semaphores have been developed to solve this problem by preventing deadlock and ensuring no philosopher starves. Monitor-based solutions with condition variables are needed to fully solve the problem without issues.

Uploaded by

Ramadan Gadah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Dining Philosophers Problem

1. What is the dining philosophers problem?

The dining philosophers problem describes a group of philosophers sitting at a table


doing one of two things - eating or thinking. While eating, they are not thinking, and
while thinking, they are not eating. The philosophers sit at a circular table each with
a bowl of spaghetti. A chopstick is placed in between each philosopher, thus each
philosopher has one chopstick to his or her left and one chopstick to his or her right.
As spaghetti is difficult to serve and eat with a single chopstick, it is assumed that a
philosopher must eat with two chopsticks. The philosopher can only use the
chopstick on his or her immediate left or right.

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).

the story of the dining philosophers as an exercise in concurrent programming in the


early 1970s

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

Devise an algorithm that will allow the philosophers to eat.

No two philosophers can use the same fork at the same time ( mutual exclusion).

No philosopher must starve to death ( avoid deadlock and starvation).

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.

4. Monitor-based Solution to Dining Philosophers

• THINKING – When a philosopher doesn’t want to gain access to either fork.

• HUNGRY – When a philosopher wants to enter the critical section.

• EATING – When the philosopher has got both the forks, i.e., he has entered
the section.

References

geeksforgeeks.org.

Jürg Gutknecht, The Dining Philosophers Problem Revisited.


https://www.researchgate.net/publication/221644832_The_Dining_Philosophers_Proble
m_Revisited/stats

You might also like