Questions: Test-and-Set and Atomic Primitives

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A thread executes test-and-set on a shared lock variable and the instruction returns 1. What should the thread do next?

AEnter the critical section — returning 1 means the lock is now acquired
BRelease the lock by writing 0 — returning 1 means the thread previously held it
CSpin and retry — returning 1 means the lock was already held by another thread
DBlock until the OS wakes it — test-and-set automatically suspends the thread when the lock is taken
Question 2 Multiple Choice

Why can't Peterson's algorithm reliably guarantee mutual exclusion on modern multicore processors without additional hardware support?

AIt uses too many shared variables for the hardware cache to track efficiently
BModern processors may reorder memory operations, breaking the assumptions Peterson's algorithm relies on
CPeterson's algorithm requires atomic increment operations that are not available on all hardware
DIt only works for two threads, so systems with more threads require a different approach
Question 3 True / False

The test-and-set instruction is atomic: no other processor can access the targeted memory location between the read and the write.

TTrue
FFalse
Question 4 True / False

Compare-and-swap (CAS) and test-and-set solve exactly the same problem in exactly the same way; CAS is simply a more recent version of the same idea.

TTrue
FFalse
Question 5 Short Answer

Why is hardware-provided atomicity necessary for synchronization on modern systems? Why isn't a careful sequence of software operations sufficient?

Think about your answer, then reveal below.