A spinlock keeps a waiter active in a loop until the lock becomes available.
It is appropriate mainly when the expected wait is short and a processor is available.
Correct Answer: C. The contents of a register and a memory location
Explanation:
An atomic swap can exchange a local value with a shared lock variable without interruption.
This indivisible exchange can be used to build mutual-exclusion locks.
Correct Answer: B. It writes a new value only if the current value equals an expected value
Explanation:
Compare-and-swap atomically verifies that a value has not changed before applying an update.
If the comparison fails, the caller can retry using the newly observed value.
Correct Answer: A. Return the old value of a memory word and set it to a new locked value
Explanation:
Test-and-set combines reading a lock value with setting it in one atomic step.
This permits multiple threads to compete for a lock without a race between separate read and write instructions.
An atomic instruction completes as one indivisible operation relative to competing processors or threads.
No observer can see or interfere with a partially completed update.
Correct Answer: C. It prevents the current code from being preempted on that processor
Explanation:
With interrupts disabled, the processor cannot switch to another interrupt-driven execution path on that CPU.
This approach is unsuitable for long user-level sections and does not by itself stop other processors.
Correct Answer: B. That the process intends to enter its critical section
Explanation:
Each flag records whether the corresponding process is interested in entering the critical section.
The other process checks this intent together with the turn value.
The classic Peterson algorithm is designed for two processes using shared flags and a turn variable.
Extensions for more processes require different or generalized algorithms.
Bounded waiting provides a finite upper bound on overtaking after a request is made.
This fairness condition prevents indefinite starvation at the critical section.
Progress requires the decision about the next entrant to involve only processes that currently wish to enter.
The selection cannot be postponed forever when the critical section is available.
Mutual exclusion prevents conflicting processes from entering the critical section simultaneously.
It is the core safety property of critical-section solutions.