Last Updated : 30 Oct, 2018

Consider the method used by processes P1 and P2 for accessing their critical sections whenever needed, as given below. The initial values of shared boolean variables flag[0] and flag[1] are false and true are initially assigned.

Process Pi: 
while(true) 
 {
   flag[i] = true; 
   while(flag[j]){/* do nothing */}; 
   CS 
   flag[i] = false; 
   RS
 } // loop forever 

Which one of the following statements describes the properties achieved?
(A) Both Mutual exclusion and progress
(B) Mutual exclusion only
(C) Both Progress and no Deadlock
(D) Both Mutual exclusion and no deadlock


Answer: (B)

Explanation: Analysis of given code:

  1. Keep one bool variable for each process: flag[0] and flag[1]; Pi signals that it is ready to enter its CS by: flag[i]=true.
  2. Mutual Exclusion is satisfied but not the Progress requirement is not satisfied since it requires strict alternation of CSs.
  3. If we have the sequence: T0: flag[0]=true; T1: flag[1]=true. Then both process will wait forever to enter their CS: we have a deadlock.

So, option (B) is correct.

Quiz of this Question


Share your thoughts in the comments