Back to Techniques for mutual exclusion:
Peterson's Solution

int turn;
int interested[2];   //all values initially 0

void enter_region(int process)
{
  int other;
  other = 1 - process;    // position 1
  interested[process]=1;  // position 2
  turn = process;         // position 3
  while(turn == process && interested[other] == 1);
}

void leave_region(int process)
{
  interested[process] = 0;
}

The following explain how it work when interrupt at position 1:
Key:   turn and interested[]are global variables.
            other is a local variable.
 
process   0
process  1
other = 1
stop, interrupt by process 1
 other = 0, interested[1] = 1, turn = 1
check while conditions: turn==1(true) and interested[0]==1(false)
then process 1 enter CS(critical section)
stop, interrupt by process 0
 process 0 get CPU now: interested[0] = 1, turn = 0
check while condition turn==0(true) and interested[1]==1(true)
then busy wait and give CPU back to process 1
process 1 keeps working then finish CS job, 
after that interested[1]=0 and give CPU to process 0
check while condition turn==0(true) and interested[1]==1(false)
then process 0 enter CS(critical section)

The following explain how it work when interrupt at position 2:
 
process   0
process   1
other = 1
interested[0] = 1
stop, interrupt by process 1
other = 0, interested[1] = 1, turn = 1
check while conditions: turn==1(true) and interested[0]==1(true)
then process 1 wait and give CPU back to process 0
process 0 get CPU now:  turn = 0
check while condition turn==0(true) and interested[1]==1(true)
then busy wait and give CPU back to process 1
check while conditions: turn==1(false) and interested[0]==1(true)
then process 1 enter CS(critical section)
stop, interrupt by process 0
check while condition turn==0(true) and interested[1]==1(true)
then busy wait and give CPU back to process 1
process 1 keeps working then finish CS job, 
after that interested[1]=0 and give CPU to process 0
check while condition turn==0(true) and interested[1]==1(false)
then process 0 enter CS(critical section)

The following explain how it work when interrupt at position 3:
 
process   0
process   1
other = 1
interested[0] = 1
turn = 0
stop, interrupt by process 1
 
other = 0, interested[1] = 1, turn = 1
check while conditions: turn==1(true) and interested[0]==1(true)
then process 1 wait and give CPU back to process 0
check while condition turn==0(false) and interested[1]==1(true)
then process 0 enter CS(critical section)
stop, interrupt by process 1
check while conditions: turn==1(true) and interested[0]==1(true)
then process 1 wait and give CPU back to process 0
process 0 keeps working then finish CS job, 
after that interested[0]=0 and give CPU to process 1
check while condition turn==1(true) and interested[0]==1(false)
then process 1 enter CS(critical section)

Note: