以下摘自这封邮件:
A process cannot be preempted nor sleep while holding a spinlock due spinlocks behavior. If a process grabs a spinlock and goes to sleep before releasing it. A second process (or an interrupt handler) that to grab the spinlock will busy wait. On an uniprocessor machine the second process will lock the CPU not allowing the first process to wake up and release the spinlock so the second process can continue, it is basically a deadlock.
This happens since grabbing an spinlocks also disables interrupts and this is required to synchronize threads with interrupt handlers.
当一个task
获得spinlock
以后,它不能被抢占(比如调用sleep
)。因为如果这时有另外一个task
也想获得这个spinlock
,在UP
系统上,这个task
就会一直占据CPU
,并且不停地尝试获得锁。而第一个task
没有机会重新执行来释放锁,这就造成“死锁”。Interrupt handler
也是同样道理。