In: Computer Science
Briefly explain the deadlock situation that can occur in the dining philosophers and how we could resolve the problem.
In Dining Philosphers Problem , there are 5 philosphers sitting around a circle and they only have 5 forks to eat which are placed on right and left of each philospher. A philospher has to use 2 forks to eat. Pphilospher thinks and eats alternatively. So we have to solve when a philospher can eat ie. when the forks are available. So we solve this problem , using semaphores which are binary variables. So when a philospher has to eat, he takes left fork first and then takes up the right fork and eats .After eating , he places forks back. If a philospher is not getting a fork ie. when some other philospher has taken that fork, then he waits for the availability of fork.
Deadlock Situation:-
Now suppose all the philosphers have picked their left fork , so right forks are not available to any of them and they starts waiting for the fork. This will create a deadlock situation ie everyone is waiting for the fork on right.
To solve this problem we change the sequence of picking up fork for one of the philospher. We change it for one of the philospher that he will pick up the right fork first and the left fork. So this situation will never go on deadlock as if 4 has taken up their left fork 1st and the 5th won't able to take up the fork to his right as its already taken. So the fork on his left will be available to another philospher. Thus there will be no deadlock.