知识卡片
锁中毒要求判断状态有效性
线程在持锁时panic可能使受保护不变量未完成,标准Mutex通过中毒状态提醒后续调用者。lock因此返回Result;选择恢复、验证后继续或终止,应依据状态能否信赖。unwrap是示例采用的策略,不代表中毒一定罕见或所有程序都应立即崩溃。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 3. Concepts Data races in Rust · 查看原书依据
poisoned. Poisoning happens if a thread fails while holding the lock, because this might mean that any mutex-protected invariants can no longer be relied on. In practice, lock poisoning is sufficiently rare (and it’s sufficiently desirable that the program terminates when it happens) that it’s common to just .unwrap() the Result (despite the advice in Item 1
参考来源
- 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第3章《Data races in Rust》(spine7;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch03.html;u102-ch03-036)。
- 结论依据:原文在“poisoned”附近的定义、例子或代码支撑本卡核心说明:线程在持锁时panic可能使受保护不变量未完成,标准Mutex通过中毒状态提醒后续调用者。边界按已读前提解释;示例未执行。
- 原始内容:poisoned. Poisoning happens if a thread fails while holding the lock, because this might mean that any mutex-protected invariants can no longer be relied on. In practice, lock poisoning is sufficiently rare (and it’s sufficiently desirable that the program terminates when it happens) that it’s common to just .unwrap() the Result (despite the advice in Item 1