@iwasifirshad A small point i would like to make clear , in normal peterson Algo what we have seen is , the process trying to enter CS will check if interested[other]==True and turn==current process(P1) , if both the conditions are met ,P1 will be busy in waiting in the while loop ( P1 will understand , there is a chance that P2 might be in CS or iterating in while loop)---
Case 1: If P2 is iterating in while loop ( interested[p1]==T && turn ==P2 is true) so as soon as P1 sets the turn=P1 , P2 will break the while loop and enter the CS
(PS- the first process to set the turn variable will get first chance to access CS )
Case 2: If P2 is in CS, P1 will iterate in the while loop untill P2 sets interested[P2]=false i.e it comes out of the CS
L1: intersted = true;
L2: turn = 2; // turn= other process
L3: while (intersted) do no-op;
L4: Enter critical section, perform actions, then
L5: exit critical section
L6: intersted = false;
L7: Perform other non-critical section actions.
L1': intersted = true;
L2': turn = 1; // other process
L3': while (intersted) do no-op;
L4': Enter critical section, perform actions, then
L5': exit critical section
L6': intersted = false;
L7': Perform other non-critical section actions.
BUT here in this question , turn variable is not used in the same way ,here turn=other process
so now how to identify the correct option , option C and D are eliminated as we always check interested [other process] == true and now setting turn=current process will violate Mutual Exclusion principle , consider Line 1,2,3 in the given code,initially interested & interested= FALSE
P1:1,2,3,CS | P2:1,2,3,CS ( violates Mutual Exclusion )
so , turn =other process ,option B is correct.