I have a query regarding the fact that how Spinlocks are advantageous in terms of context switching ?
1 Answer
$\begingroup$
$\endgroup$
2
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$– radhikaCommented Oct 29, 2019 at 14:43
-
$\begingroup$ Consider a lock that is released after a nanosecond. What happens? $\endgroup$ Commented Oct 29, 2019 at 20:53