a) P:flag[j]=true and S1!=S2
Q:flag[i]=true and S1==S2
Initially , flag[i]=flag[j]=false.
P1 will make flag[i] =false, true and Make S1=S2 so , if P:flag[j]=true and S1==S2 then P will be false hence no waiting in loop. So P1 will enter the CS.
Now check that P2 can enter the CS or not when P1 is in CS.
P2 will make flag[j]= false ,true and make S1=S2+1, so ,if Q:flag[i]=true and S1==S2 then Q will be false hence no waiting in loop. So, P2 will enter the CS.
So, both processes will enter the critical section.
Hence, option (a) is false.
b) P:flag[j]=true and S1==S2
Q:flag[i]=true and S1!=S2
P1 will make flag[i] =false, true and Make S1=S2 so , if P:flag[j]=true and S1==S2 then P will be false as flag[j]=false, hence no waiting in loop. So P1 will enter the CS.
Now check that P2 can enter the CS or not when P1 is in CS.
P2 will make flag[j]= false ,true and make S1=S2+1, so ,if Q:flag[i]=true and S1!=S2 then Q will be true as (flag[i]=true and S1!=S2)=TRUE, hence,P2 will wait in the loop.
So, only one process will enter the critical section.
Hence, option (b) is true.
c) P:flag[i]=true and S1!=S2
Q:flag[j]=true and S1==S2
P1 will make flag[i] =false, true and Make S1=S2 so, if P:flag[i]=true and S1!=S2 then P will be false hence no waiting in loop. So P1 will enter the CS.
Now check that P2 can enter the CS or not when P1 is in CS.
P2 will make flag[j]= false ,true and make S1=S2+1, so ,if Q: flag[j]=true and S1!=S2then Q will be false hence no waiting in loop. So, P2 will enter the CS.
So, both processes will enter the critical section.
Hence, option (c) is false.
d) P:flag[i]=true and S1==S2
Q:flag[j]=true and S1!=S2
P1 will make flag[i] =false, true and Make S1=S2 so, if P:flag[i]=true and S1==S2 then P will be true hence waiting in loop. So P1 will not enter the CS.
Now check for P2 ,
P2 will make flag[j]= false ,true and make S1=S2+1, so ,if Q: flag[j]=true and S1!=S2then Q will be TRUE hence waiting in loop. So, P2 cannot enter the CS.
But Now, if again preemption happens, then P2 has made S1!=S2 So,P1 can enter the CS and P2 will wait in the loop. So, mutual exclusion holds.
Hence, option (d) is true.
Correct me if i am wrong