CS FundamentalsVery hardGATE CS · Amazon/Microsoft SDE MCQ

Why is a test-and-test-and-set spinlock (spin on a plain read, and only try the atomic exchange when the lock looks free) usually faster than spinning directly on test-and-set on a multicore machine?

  1. A. It guarantees FIFO fairness among all the waiting threads
  2. B. Spinning on reads stays in the local cache instead of flooding the bus
  3. C. It disables interrupts while spinning, so no context switch can occur
  4. D. It avoids the need for any atomic read-modify-write instruction at all

Correct answer: B. Spinning on reads stays in the local cache instead of flooding the bus

Each test-and-set is a write that invalidates the line in every other cache, so spinning on it causes constant coherence traffic. Spinning on a read stays in the local cache until the holder's release invalidates it. It is still unfair and still needs the atomic step.

More Operating Systems questions

Exams that ask this topic