Medium Operating Systems Synchronization
When would you use a spinlock vs a mutex?
Answer
Spinlock busy-waits (spins) checking lock status, consuming CPU but avoiding context switch overhead. Mutex blocks the thread, triggering context switch. Use spinlock when: critical section is very short, multiprocessor system, lock hold time < context switch time. Use mutex when: longer critical sections, single processor (spinning wastes cycles), or when sleeping is acceptable. Hybrid adaptive mutexes spin briefly then sleep. Spinlocks shouldn't be used in user space on single core.
IIT Certified
Master These Concepts with IIT Certification
175+ hours of industry projects. Get placed at Bosch, Tata Motors, L&T and 500+ companies.
Relevant for Roles
Systems Developer Performance Engineer OS Developer