What are common reasons for deadlocks?

后端 未结 12 996
清酒与你
清酒与你 2020-12-13 00:16

Deadlocks are hard to find and very uncomfortable to remove.

How can I find error sources for deadlocks in my code? Are there any \"deadlock patterns\"?

In m

12条回答
  •  感情败类
    2020-12-13 00:55

    The classic deadlock scenario is A is holding lock X and wants to acquire lock Y, while B is holding lock Y and wants to acquire lock X. Since neither can complete what they are trying to do both will end up waiting forever (unless timeouts are used).

    In this case a deadlock can be avoided if A and B acquire the locks in the same order.

提交回复
热议问题