edited by
17,848 views
37 37 votes

A solution to the Dining Philosophers Problem which avoids deadlock is to

  1. ensure that all philosophers pick up the left fork before the right fork

  2. ensure that all philosophers pick up the right fork before the left fork

  3. ensure that one particular philosopher picks up the left fork before the right fork, and that all other philosophers pick up the right fork before the left fork

  4. None of the above

6 Answers

Best answer
44 44 votes

Acc. to me it should be (C) because: according to condition, out of all, one philosopher will get both the forks. So, deadlock should not be there.

edited by
16 16 votes
option C explanation:-

let A,B,C are the three philosophers .....

let A pickup left before right and all other pickup right before left then...now B has picked up right fork and A has picked up left fork ....

and  C is waiting for A ....

now both left and right fork is available for A.(i.e A would finish)...after A ,B and then C......

no deadlock....
7 7 votes

Another way to think is first two options forms a cycle that is a circular wait and all other necsessary conditions are satisfied for dining philosopher's problem. So those two are not possible and third one breaks this circular wait. So it is the correct answer.

7 7 votes

In the Dining Philosophers Problem,

each philosopher needs exactly two chopsticks to eat food but the problem is: each philosopher is going to take one chopstick at a time, which is placed at its right-hand side or at its left-hand side, but remember all should choose in same the manner like it first one chooses in a clockwise manner then each one should choose in clockwise, this type of picking  causes a circular waiting loop because each one is depending on other. This is also called as circular waiting and it leads to deadlock.

To avoid this, at least one philosopher should choose its first chopstick in different way so that that circular loop is not formed.

edited by
1 1 vote

There are multiple ways to break a deadlock, which are as follows:

1) You bring in more resources (not a good solution but still a possible way)

2)You choose one lesser No of Philosophers than given ie., create a room by using P() at start of each Philosophers turn and ensure that signal V()  is there at end of given philosophers only which ensures if 5 philophers are given and 5 forks then only 4 philophers are choosen first once one finishes eating fully another is allowed to come

3)You can also break the symmtery , there are many ways to do so one of them could be to ask one of them to pick right fork while all others pick the fork on their left.

4)All of Nothing, which means that a given person either picks both forks or does not pick anything, this also ensures that no deadlock occurs 

Here, option (c) matches with one of the methods hence it is correct.

Also, note that for n people you will need min of n+1 forks to avoid deadlock.

(source - goclasses slides)

edited by
0 0 votes
Deadlock occurs when – The first choice fork of every philosopher is different. For example every philosopher just grabs the fork on their left first.

To avoid this scenario the first choice of atleast one philosopher must be different than the others.

So option (C) is correct.
Answer:
Position:
Show:

Related questions

38 38 votes
1 answers 1 answer
9.6k
9.6k views
Kathleen asked Oct 9, 2014
9,648 views
The concurrent programming constructs fork and join are as below:Fork <label which creates a new process executing from the specified labelJoin <variable which decrements...
29 29 votes
1 answers 1 answer
8.7k
8.7k views
Kathleen asked Oct 9, 2014
8,741 views
A critical section is a program segmentwhich should run in a certain amount of timewhich avoids deadlockswhere shared resources are accessedwhich must be enclosed by a pa...
3 3 votes
1 answers 1 answer
2.2k
2.2k views
Kathleen asked Oct 9, 2014
2,184 views
Consider the following program in pseudo-Pascal syntax. What is printed by the program if parameter $a$ in procedure $\text{test1}$ is passed ascall-by-reference paramete...
33 33 votes
4 answers 4 answers
15.1k
15.1k views
Kathleen asked Oct 9, 2014
15,087 views
Four jobs to be executed on a single processor system arrive at time $0$ in the order $A, B, C, D$. Their burst CPU time requirements are $4, 1, 8, 1$ time units respecti...