知识卡片
手写并发标记的义务
Send 和 Sync 没有方法,编译器通常根据字段自动推导。需要手写 unsafe impl 时,作者必须维护所声明的安全性质,因为调用者会据此跨线程转移值或共享引用。一个编译通过的 unsafe impl 无法证明其计数或运行时借用机制正确,先考虑能否由标准同步类型组合出所需性质。
相关卡片 [[跨线程的两种标记]]
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 无畏并发 Extensible Concurrency with the Send and Sync Traits · 查看原书依据
Manually implementing these traits involves implementing unsafe Rust code. We’ll talk about using unsafe Rust code in Chapter 19; for now, the important information is that building new concurrent types not made up of Send and Sync parts requires careful thought to uphold the safety guarantees. “The Rustonomicon” at https://doc.rust-lang.org/stable/nomicon has more information about these guarantees and how to uphold them.
参考来源
- 位置:《The Rust Programming Language(第2版)》第16章 无畏并发(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c16.xhtml`,块 0192)
- 结论依据:原文说明手动实现需要 unsafe,并要求新并发类型维护相应的安全保证。
- 原始内容:Manually implementing these traits involves implementing unsafe Rust code. We’ll talk about using unsafe Rust code in Chapter 19; for now, the important information is that building new concurrent types not made up of Send and Sync parts requires careful thought to uphold the safety guarantees. “The Rustonomicon” at https://doc.rust-lang.org/stable/nomicon has more information about these guarantees and how to uphold them.