Questions: Software-Only Mutual Exclusion Solutions

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

In Peterson's algorithm for two processes, what is the purpose of setting `turn` to the *other* process's ID when a process wants to enter the critical section?

AIt signals that the other process should get out of the critical section immediately
BIt claims priority — whoever sets turn to the other's ID gets to go first
CIt is an act of deference — 'you go first if you want to' — so that whoever defers last is the one that waits
DIt resets the other process's flag variable to false
Question 2 Multiple Choice

A colleague tells you Peterson's algorithm fails reliably on modern x86 and ARM hardware, even though it is provably correct under sequential consistency. What is the most likely cause?

AModern CPUs execute instructions too quickly for the flag mechanism to have effect
BPeterson's algorithm only handles two processes, but modern kernels always schedule more
CCPUs and compilers reorder memory reads and writes for performance, so the flag write may not be visible to the other process before the turn read occurs
DThe algorithm assumes processes run at the same speed, which hardware cannot guarantee
Question 3 True / False

A mutual exclusion solution that uses primarily a `flag` array (with no `turn` variable) can satisfy most three critical section requirements: mutual exclusion, progress, and bounded waiting.

TTrue
FFalse
Question 4 True / False

Peterson's algorithm guarantees bounded waiting — no process waiting to enter the critical section will wait indefinitely.

TTrue
FFalse
Question 5 Short Answer

Explain why Peterson's algorithm, which is provably correct under sequential consistency, fails on modern hardware, and what this implies about the need for hardware support for mutual exclusion.

Think about your answer, then reveal below.