Consider the simplified versions of code for P0 and P1
[You can ignore line 14 and 30 for now]
Assume initally turn = 1
So we have
FLAG = [FALSE, FALSE]
turn = 1
P0 starts initally
=====================================================================================
executes line 3: flag[0]:= true;
So we have
FLAG = [TRUE, FALSE]
turn = 1
executes line 5: while (turn != 0) // here turn is 1, so go inside the body
executes line 7: while (flag [1] == True); // here condition is false, so go to next line
P0 now preempts
=====================================================================================
Just before executing line 8, P0 preempts
Upon returning back, it will execute at line 8
turn=0;
So we have
FLAG = [TRUE, FALSE]
turn = 1
P1 starts nextly
=====================================================================================
executes line 19: flag[1]:= true;
So we have
FLAG = [TRUE, TRUE]
turn = 1
executes line 21: while (turn != 1) // here turn is 1, so go inside the CS
executes line 27: [Critical Section] //P1 currently enjoying CS
P1 now preempts
=====================================================================================
P1 while holding CS preempts
Upon returning back, it will resume at line 27
[Critical Section]
P0 now resumes
=====================================================================================
executes line 8: turn=0;
So we have
FLAG = [TRUE, TRUE]
turn = 0
executes line 8: turn=0;
executes line 5: while (turn != 0) // here turn is 0, so go inside the CS
executes line 27: [Critical Section] //P0 currently enjoying CS
Now, P0 entered CS when P1 is already holding CS, so mutual exclusion is violated