开发者

Kernel preemption while holding spinlock

开发者 https://www.devze.com 2023-02-15 09:11 出处:网络
In the linux kernel, if kernel preemption is enabled while 开发者_Go百科holding a spinlock, how candeadlock occur ?Kernel preemption doesn\'t guarantee that you don\'t have a deadlock.

In the linux kernel, if kernel preemption is enabled while 开发者_Go百科holding a spinlock, how can deadlock occur ?


Kernel preemption doesn't guarantee that you don't have a deadlock.

A thread may still hold a lock without ever releasing it, and that would still cause a deadlock if some other thread wants to acquire that same lock. The thread that is holding the lock has to decide to release it to avoid deadlocks. That is to say the thread or some other logic has to preempt the thread and cause it to release the lock. The kernel itself can't cause the thread to release the lock.

The kernel simply can schedule other threads to run, but if some other thread depends on the first thread finishing then that thread will also get blocked.

For example:

Thread A is waiting on a lock for some shared resource that thread B has acquired.

Thread A get's preempted and thread B gets scheduled.

Thread B is waiting on a lock for some shared resource thread A is holding.

Deadlock. Neither thread A nor thread B can make progress.

To break the deadlock something has to preempt thread A or B to release it's lock. Kernel preemption can't do that.

0

精彩评论

暂无评论...
验证码 换一张
取 消