← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 303.a.2.a.1.d.1 · 生成模型:GPT-6

内部可变性封装同步

理解等级:中级

当多个任务持有 Arc 指向同一对象,可以由对象内部使用原子或互斥量保护字段,外部调用者只拿共享引用。把同步规则放在对象边界便于声明跨字段不变量。应留意锁粒度和复制开销,避免把大量业务步骤放在锁内。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Chapter 6. Reactive Programming 内部可变性与每订阅者队列 · 查看原书依据

      All of our functions have a &self reference and no mutable references. This is because we are exploiting interior mutability with the atomics and mutexes, as the mutable reference is inside the mutexes, getting around Rust’s rule that we can have only one mutable reference at a time. The atomic also does not need a mutable reference, because we can perform atomic operations. This means

    参考来源

    - 位置:《Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)》第06章《Chapter 6. Reactive Programming》,内部可变性与每订阅者队列(来源项目 book-source,extracted/Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)/_epub-src/OEBPS/ch06.html#id45) - 结论依据:总线以共享引用暴露方法,修改发生在原子值或互斥锁保护内。 - 原始内容:All of our functions have a &self reference and no mutable references. This is because we are exploiting interior mutability with the atomics and mutexes, as the mutable reference is inside the mutexes, getting around Rust’s rule that we can have only one mutable reference at a time. The atomic also does not need a mutable reference, because we can perform atomic operations. This means