3

Dining Philosophers Problem in Operating Systems (OS)

 1 year ago
source link: https://www.geeksforgeeks.org/videos/dining-philosophers-problem-in-operating-systems-os/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Dining Philosophers Problem in Operating Systems (OS)

Dining Philosophers Problem in Operating Systems (OS)
  • 30 Views
  • 11/10/2022

Let's discuss the dining philosophers' problem in Operating systems in detail in this video.

In the dining philosophers process synchronization problem, there are 5 philosophers sitting at a dining table each with a plate in front of them. There is a fork between every pair of plates. At any point, each philosopher can either eat or think. 

So the problem is every philosopher requires two forks to eat and the philosopher can pick any one fork at a time either left or right fork. If every philosopher picks one fork, then there will be a deadlock. So we need to design such a set of instructions that can prevent deadlock. 

The situation is that 2 philosophers cannot pick up two forks at the same time, and each philosopher gets a chance to eat in a certain finite time. When a few philosophers are waiting then one gets a chance to eat for some time, this means no philosopher suffers from starvation. There is no strict alteration between philosophers. 

The solution to this problem using semaphore is that an asymmetric algorithm is used in which the first four philosophers execute the same solution but the fifth philosopher waits for the right fork and then for the left fork. 

The solution to this problem by using the monitor is that it maintains an array of the fork which counts the number of free forks available to each philosopher. The take_forks operation waits on a condition variable until two forks are available. It decrements the number of forks available to its neighbour before leaving the monitor. After eating, a philosopher calls release_forks which updates the array fork and checks if freeing forks makes it possible to signal. 

Dining philosopher's problem using semaphores: https://www.geeksforgeeks.org/dining-philosopher-problem-using-semaphores/
Dining philosopher's problem: https://www.geeksforgeeks.org/dining-philosophers-problem/


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK