知识卡片
跨线程转移与共享分开约束
Send约束值的跨线程转移,Sync约束共享引用的跨线程使用,即T:Sync时&T可Send。它们是编译器按组成推导的自动trait,必要时也有明确排除。Rc的计数不支持并发,Cell或RefCell的内部可变性也不自动支持并发共享;能移动与能共享是不同能力。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 3. Concepts Standard marker traits · 查看原书依据
Standard marker traits There are two standard traits that affect the use of Rust objects between threads. Both of these traits are marker traits (Item 10) that have no associated methods but have special significance to the compiler in multithreaded scenarios: The Send trait indicates that items of a type are safe to transfer between threads; ownership of an
参考来源
- 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第3章《Standard marker traits》(spine7;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch03.html;u103-ch03-037)。
- 结论依据:原文在“Standard marker traits”附近的定义、例子或代码支撑本卡核心说明:Send约束值的跨线程转移,Sync约束共享引用的跨线程使用,即T:Sync时&T可Send。边界按已读前提解释;示例未执行。
- 原始内容:Standard marker traits There are two standard traits that affect the use of Rust objects between threads. Both of these traits are marker traits (Item 10) that have no associated methods but have special significance to the compiler in multithreaded scenarios: The Send trait indicates that items of a type are safe to transfer between threads; ownership of an