The key point is the Linux kernel, in which locking the lock will disable prevention. Thus, sleeping while holding a spin lock can potentially cause a dead end.
For example, thread A receives a spin lock. Thread A will not be unloaded until it releases the lock. As long as thread A quickly does its job and releases the lock, there is no problem. But if thread A sleeps while holding the lock, thread B can be scheduled since the sleep function will call the scheduler. And thread B could get the same lock. Thread B also disables prevention and attempts to obtain a lock. And there is a dead end. Thread B will never get a lock, since thread A holds it, and thread A will never start, since thread B disables prevention.
And why is disabling preemptive use in the first place? I suppose because we don’t want threads on other processors to wait too long.
Nan wang
source share