知识卡片
原子计数不等于内部线程安全
Arc通过原子计数管理共享所有权,不能自动让内部T安全并发修改。共享可变状态常需Mutex等机制,且T自身仍受Send、Sync条件限制。原书说Arc完全不能取得可变访问过于绝对:唯一拥有等条件下get_mut可返回可变引用,这与共享修改是不同情况。
边界依据:Arc::get_mut官方文档,2026-10-27查阅。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 1. Types Smart Pointer Types · 查看原书依据
Arc<T>, which uses atomic counters to ensure that the reference counts remain accurate. Like Rc, Arc implements all of the various pointer-related traits. However, Arc on its own does not allow any kind of mutable access to the underlying item. This is covered by the Mutex type, which ensures that only one thread has access—whether mutably or immutably—to th
参考来源
- 位置:《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-068)。
- 结论依据:原文在“Arc<T>”附近的定义、例子或代码支撑本卡核心说明:Arc通过原子计数管理共享所有权,不能自动让内部T安全并发修改。边界按已读前提解释;示例未执行。
- 原始内容:Arc<T>, which uses atomic counters to ensure that the reference counts remain accurate. Like Rc, Arc implements all of the various pointer-related traits. However, Arc on its own does not allow any kind of mutable access to the underlying item. This is covered by the Mutex type, which ensures that only one thread has access—whether mutably or immutably—to th