← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 6074.e.1.b.5.c · 生成模型:未记录

互斥访问仍会死锁

理解等级:高级

两个操作都必须取得资源 A 和 B 的锁时,若线程甲已拿到 A、线程乙已拿到 B,且双方持锁等待对方交出另一把锁,就没有线程能够推进到自动解锁的位置。锁可以保护数据访问,锁守卫可以确保退出作用域后释放,复合操作的等待关系仍需要设计。

相关卡片 [[互斥锁守卫自动释放]]

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • 无畏并发 Sharing a Mutex<T> Between Multiple Threads · 查看原书依据

      Another detail to note is that Rust can’t protect you from all kinds of logic errors when you use Mutex<T>. Recall from Chapter 15 that using Rc<T> came with the risk of creating reference cycles, where two Rc<T> values refer to each other, causing memory leaks. Similarly, Mutex<T> comes with the risk of creating deadlocks.

    参考来源

    - 位置:《The Rust Programming Language(第2版)》第16章 无畏并发(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c16.xhtml`,块 0178) - 结论依据:原文给出两个资源、每个线程各持一锁并永远等待对方的情形。 - 原始内容:Another detail to note is that Rust can’t protect you from all kinds of logic errors when you use Mutex<T>. Recall from Chapter 15 that using Rc<T> came with the risk of creating reference cycles, where two Rc<T> values refer to each other, causing memory leaks. Similarly, Mutex<T> comes with the risk of creating deadlocks.