CS FundamentalsHardGATE CS

A spinlock is held for about 50 ns on average, and a context switch costs about 5 µs. On a multicore machine, which is better for a thread that finds the lock busy?

  1. A. Block immediately, because spinning always wastes CPU
  2. B. Spin, because the expected wait is far shorter than two context switches
  3. C. Disable interrupts on all cores
  4. D. Spin only on a single-core machine

Correct answer: B. Spin, because the expected wait is far shorter than two context switches

Blocking costs at least a switch out and a switch back (~10 µs), much more than a 50 ns wait. On a single core spinning is useless, because the holder cannot run while the waiter spins.

More Operating Systems questions

Exams that ask this topic