1,430 views
2 votes
2 votes

Consider the below Algorithm where flag and lock are global variables:


P0:                                                                                    P1:
while (flag= =1 && lock= = 0);                                    while (flag= = 0 && lock= = 1);
Enter CS                                                                          Enter CS
lock= 0                                                                             flag= 0
flag= 1
                                                                              lock= 1

(a) The above algorithm is deadlock free
(b) The above algorithm guarantees Mutual Exclusion
(c) Both (a) & (b)
(d) None of the above

2 Answers

Best answer
5 votes
5 votes
Let flag=0 & lock=0, then both the processes can enter the CS simultaneously.

So, mutual exclusion is not satisfied.

The implementation of the system is such that once a process make it to its critical section it sets the value of flag & lock such that both the processes can enter their CS alternatively i.e. either P0->P1->P0->P1->......... OR P1->P0->P1->P0->.........

Starvation for a process is possible if the other process that is expected in the sequence is not present.

The solution is deadlock free as both the processes are never simultaneously waiting in the while loop.

So, answer is (A)
selected by
3 votes
3 votes
Answer A:

As mutual exclusion is one of the conditions for deadlock to take place and here mutual exclusion is not satisfied. Therefore no deadlock!

Related questions

0 votes
0 votes
1 answer
2
ajayraho asked Oct 23, 2022
876 views
What is the significance of infinite loop that is written in every example of process synchronisation? What would happen if there wasn't any infinite loop?