Spinning On One Core

A single-core machine runs two threads with a 10 ms scheduling quantum. Thread A takes a spinlock, and 50 ns later the timer interrupt preempts it inside the critical section. Thread B is scheduled next and immediately tries to take the same spinlock.

The critical section is 200 ns of work in total. How much CPU time is burned before B gets the lock?

A

Effectively zero: the hardware detects the spin loop and yields the core to the lock holder.

B

About 200 ns: B spins only for as long as the critical section still has left to run.

C

About 10 ms: B spins away its entire quantum, because A cannot finish the critical section until B is descheduled.

D

About 400 ns: one context switch out and one back, each roughly the length of the critical section.