知识卡片

普通读书笔记卡 · 6074.e.1.b.7

逆序嵌套加锁形成等待环

理解等级:中级

add_and_join先锁players再锁games,ban_player顺序相反;两线程各持第一把锁再等第二把时,就形成死锁。数据竞争被锁防住,不代表等待进度也有保证。等待环可跨更多锁与线程,定位时需查看完整取得顺序。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Chapter 3. Concepts Deadlocks · 查看原书依据

      lock inversion: one function acquires the locks in the order players then games, whereas the other uses the opposite order (games then players). This is a simple example of a more general problem; the same situation can arise with longer chains of nested locks (thread 1 acquires lock A, then B, then it tries to acquire C; thread 2 acquires C, then tries to a

    参考来源

    - 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第3章《Deadlocks》(spine7;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch03.html;u104-ch03-038)。 - 结论依据:原文在“lock inversion”附近的定义、例子或代码支撑本卡核心说明:add_and_join先锁players再锁games,ban_player顺序相反;两线程各持第一把锁再等第二把时,就形成死锁。边界按已读前提解释;示例未执行。 - 原始内容:lock inversion: one function acquires the locks in the order players then games, whereas the other uses the opposite order (games then players). This is a simple example of a more general problem; the same situation can arise with longer chains of nested locks (thread 1 acquires lock A, then B, then it tries to acquire C; thread 2 acquires C, then tries to a