October 2017
Intermediate to advanced
586 pages
14h 8m
English
Like mutex, spinlock is a mutual exclusion mechanism; it only has two states:
Any thread that needs to acquire the spinlock will active-loop until the lock is acquired, which breaks out of the loop. This is the point where mutex and spinlock differ. Since spinlock heavily consumes the CPU while looping, it should be used for very quick acquires, especially when the time to hold the spinlock is less than the time to reschedule. Spinlock should be released as soon as the critical task is done.
In order to avoid wasting CPU time by scheduling a thread that may probably spin, trying to acquire a lock held by another thread moved off the run queue, the kernel disables preemption whenever code holding ...