知识卡片
Pin保护自引用
Pin 为地址敏感的值提供稳定性契约。固定 Box 所指的值后,移动 Box 这个句柄与移动其堆上内容有不同后果。async move 转移捕获值的所有权,这个语义本身并未建立固定。不要照抄书中裸指针解引用反例来检查地址。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 2. Basic Async Rust Pin 保护地址稳定 · 查看原书依据
If you try to run the code, you will get an error, which is likely a segmentation fault. A segmentation fault is an error caused by accessing memory that does not belong to the program. We can see that moving a struct with a reference to itself can be dangerous. Pinning ensures that the future remains at a fixed memory address. This is important because
参考来源
- 位置:《Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)》第02章《Chapter 2. Basic Async Rust》,Pin 保护地址稳定(来源项目 book-source,extracted/Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)/_epub-src/OEBPS/ch02.html#id12)
- 结论依据:原书移动携带自引用裸指针的结构体,展示地址改变会令引用失效。
- 原始内容:If you try to run the code, you will get an error, which is likely a segmentation fault. A segmentation fault is an error caused by accessing memory that does not belong to the program. We can see that moving a struct with a reference to itself can be dangerous. Pinning ensures that the future remains at a fixed memory address. This is important because