Why can't you sleep while holding spinlock?

前端 未结 8 2022
醉梦人生
醉梦人生 2020-12-08 12:17

In the linux kernel, why can\'t you sleep while holding a spinlock?

8条回答
  •  甜味超标
    2020-12-08 12:27

    total agree with Nan Wang. I guess most important concept is "preemption" & "scheduling" and how happen when spinlock is acquired. when spinlock is acquired, preemption is disabled(true or not, I don't know, but assume it is correct), it means timer interrupt can't preempt current spinlock holder, but current spinlock hold still call sleepable kernel functions & actively invoke scheduler & run "another task". if "another task" happened to want to acquire the same spinlock as the first spinlock holder, here is problem come: since preemption is already disabled by first spinlock holder, "another task" which is invoked by actively call of scheduler by first spinlock holder, can't be preempted out, so its spinning always take the cpu, this is why deadlock happen.

提交回复
热议问题