Practice mode Operating Systems

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

Explanation

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.