← 返回刚才阅读的位置

知识卡片

问题卡 · 1714.e

反向持锁造成循环等待

理解等级:中级

线程一先拿A再等B,线程二先拿B再等A;若各已持有第一把锁,两者都无法释放,工作线程被永久占用。隐藏在数据库查询里的锁也可能参与循环,所以仅观察显式互斥量不够。超时前系统可能已明显变慢,超时错误应记录并调查,不能因为最终报错就认为并发设计安全。

[[一致资源顺序打断死锁环]]针对的正是这类反向获取产生的等待环。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • 构建稳定系统 · 查看原书依据

      If Thread 2 acquires lockb after Thread 1 acquires locka, we have a deadlock. If in Thread 2 we move locka.aquire() as the first statement, then a deadlock is not possible because if we get locka, it is guaranteed that lockb is available.

    参考来源

    - 位置:《Software Architecture and Decision-Making》第12章《Building Stable Systems》(来源项目:book-sources;源文件:extracted/Software Architecture and Decision-Making Leveraging Leadership, Technology, and Product Management to Build Great Products… (Srinath Perera)/_epub-src/ch12.xhtml) - 结论依据:摘录说明线程一先拿A再等B,线程二先拿B再等A;若各已持有第一把锁,两者都无法释放,工作线程被永久占用。其余条件结合本章相邻例子与取舍说明,数字示例不作当前性能承诺。 - 原始内容:If Thread 2 acquires lockb after Thread 1 acquires locka, we have a deadlock. If in Thread 2 we move locka.aquire() as the first statement, then a deadlock is not possible because if we get locka, it is guaranteed that lockb is available.