知识卡片

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

锁与数据绑定约束访问路径

理解等级:中级

Mutex包住受保护数据,取得锁后通过守卫访问;普通安全代码不能像独立锁和裸字段那样随意漏掉访问协议。账户withdraw需在同一守卫下检查并扣减。它强化单次访问约束,但若把业务步骤拆成多次持锁,仍可能重新引入逻辑竞态。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Chapter 3. Concepts Data races in Rust · 查看原书依据

      MutexGuard object with RAII behavior, like C++’s std::lock_guard: the mutex is automatically released at the end of the scope when the guard is dropped. (In contrast to C++, Rust’s Mutex has no methods that manually acquire or release the mutex, as they would expose developers to the danger of forgetting to keep these calls exactly in sync.) To be more preci

    参考来源

    - 位置:《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-034)。 - 结论依据:原文在“MutexGuard object”附近的定义、例子或代码支撑本卡核心说明:Mutex<T>包住受保护数据,取得锁后通过守卫访问;普通安全代码不能像独立锁和裸字段那样随意漏掉访问协议。边界按已读前提解释;示例未执行。 - 原始内容:MutexGuard object with RAII behavior, like C++’s std::lock_guard: the mutex is automatically released at the end of the scope when the guard is dropped. (In contrast to C++, Rust’s Mutex has no methods that manually acquire or release the mutex, as they would expose developers to the danger of forgetting to keep these calls exactly in sync.) To be more preci