Questions: Spinlocks and Busy-Waiting Synchronization

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

Thread A holds a lock while updating a single pointer — an operation that takes about 20 nanoseconds. Thread B wants the same lock. A context switch costs approximately 1–5 microseconds. Which synchronization choice is most efficient for Thread B?

AA blocking mutex, because it avoids wasting CPU cycles while waiting
BA spinlock, because the expected wait (20ns) is far less than the context switch cost (1000–5000ns)
CA spinlock, because spinlocks are always more efficient than blocking locks
DA blocking mutex, because spinlocks can only be used in kernel code
Question 2 Multiple Choice

On a single-processor system, thread A holds a spinlock and thread B is spinning on it. What happens?

AThread B acquires the lock quickly because thread A will finish its critical section before the scheduler intervenes
BThread B burns its entire time slice while thread A cannot run to release the lock — the spin is pure waste until the OS preempts thread B
CThe OS detects the spin pattern and automatically converts it to a blocking wait
DThread A is immediately preempted by the scheduler when thread B starts spinning
Question 3 True / False

Spinlocks rely on atomic hardware instructions like test-and-set or compare-and-swap to ensure that only one thread enters the critical section at a time.

TTrue
FFalse
Question 4 True / False

Spinlocks are typically more efficient than blocking locks because they avoid the overhead of context switches.

TTrue
FFalse
Question 5 Short Answer

Why are spinlocks used inside OS kernels for protecting short critical sections, and what would go wrong if kernel code tried to use a blocking mutex instead?

Think about your answer, then reveal below.