Peterson’s solution to the critical-section problem for two processes uses which shared variables?
Correct answer C. A boolean array flag[2] and an integer turn
In Peterson's algorithm a process sets flag[i] to true to show it wants to enter, then sets turn to the other process, and waits while the other's flag is true and it is the other's turn. Together the two variables give mutual exclusion, progress and bounded waiting with no special hardware. On modern CPUs that reorder memory accesses it needs memory barriers to be correct.
Answer checked How we write and check questions
Discussion