I have a query regarding the fact that how Spinlocks are advantageous in terms of context switching ?


1 Answer 1


Ask yourself why you use a context switch in a lock operation in the first place. What are the benefits and the disadvantages?

Now ask yourself if there are situations where the benefits are slim. How does a spin lock minimise the disadvantages of a normal lock operation?

Consider the cases where a lock is released after a minute, second, millisecond, microsecond or nanosecond.

  • $\begingroup$ Till the process is granted lock ,it will be in ready queue only. Each time it will be scheduled on CPU ,it will be simply doing nothing except for checking again and again whether the lock is available and when time quantum is over , context switching will be done and new process will be scheduled ,so how can we say that there is no context switching ? $\endgroup$
    – radhika
    Oct 29, 2019 at 14:43
  • $\begingroup$ Consider a lock that is released after a nanosecond. What happens? $\endgroup$
    – gnasher729
    Oct 29, 2019 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.