知识卡片

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

锁守卫约束共享访问

理解等级:中级

Mutex的lock返回守卫,通过守卫访问内部值,并在守卫释放时解锁。RwLock则允许多个读者或一个写者,适合读多写少的候选场景,但仍应按开销与调度评估。锁能限制并发访问,却不会自动排除死锁、错误锁范围或跨多步操作的竞态。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Chapter 1. Types Smart Pointer Types · 查看原书依据

      MutexGuard, which implements Deref[Mut]. If there are likely to be more readers than writers, the RwLock type is preferable, as it allows multiple readers access to the underlying item in parallel, provided that there isn’t currently a (single) writer. In either case, Rust’s borrowing and threading rules force the use of one of these synchronization containe

    参考来源

    - 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第1章《Smart Pointer Types》(spine5;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch01.html;u046-ch01-069)。 - 结论依据:原文在“MutexGuard”附近的定义、例子或代码支撑本卡核心说明:Mutex的lock返回守卫,通过守卫访问内部值,并在守卫释放时解锁。边界按已读前提解释;示例未执行。 - 原始内容:MutexGuard, which implements Deref[Mut]. If there are likely to be more readers than writers, the RwLock type is preferable, as it allows multiple readers access to the underlying item in parallel, provided that there isn’t currently a (single) writer. In either case, Rust’s borrowing and threading rules force the use of one of these synchronization containe