Statistics:
mean 39.905 (838.000/21) stddev 5.528 median 41.000 midrange 34.000-42.750
Suppose we exchange the first two lines of lock().void lock() { interested[me] = true; turn = other; while(turn != me && interested[other]); } void unlock() { interested[me] = false; }
This approach is no longer correct. Explain what is wrong, giving a detailed step-by-step trace that exemplifies the problem.void lock() { turn = other; interested[me] = true; while(turn != me && interested[other]); }
This does not have mutual exclusion. The following
time sequence illustrates a situation where this occurs.
At this point, both A and B have managed to enter their critical
sections.
B: turn = A
A: turn = B
A: interested[A] = true
A: while(turn != A && interested[B]);
A: enters critical section (since interested[B] == false)
B: interested[B] = true;
B: while(turn != B && interested[A]);
B: enters critical section (since turn == B)