the above solution for critical section isn't correct because it satisfies Mutual exclusion and Progress but it violates the bounded waiting.
here is sample run
suppose turn =j initially;
Pi runs its first statement then Pj runs its first statement then Pi run 2,3,4 statement, It will block on statement 4
Now Pj start executing its statements goes to critical section and then flag[j]=false
Now suppose Pj comes again immediately after execution then it will again execute its critical section and then flag[j]=false
Now if Pj is coming continuously then process Pi will suffer starvation
the correct implementation ( for Bounded waiting ) is, at the exit section we have to update the turn variable at exit section.
while turn != i
while flag [j] do skip
turn = j;