知识卡片

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

跨线程任务类型边界

理解等级:中级

Send 允许所有权在线程之间转移。’static 类型界限要求计算不借用寿命更短的局部值,拥有 String 等值的任务仍可立即完成和释放。async move 可以把所捕获的值搬进 Future,捕获的值若仍是短借用,单靠 move 无法延长所借对象寿命。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)》第03章《Chapter 3. Building Our Own Async Queues》,任务入口、运行令牌和计时(来源项目 book-source,extracted/Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)/_epub-src/OEBPS/ch03.html#id17) - 结论依据:通用 spawn 要求 Future 与输出 Send + 'static,并解释不确定的任务寿命。 - 原始内容:The static means that our future does not contain any references that have a shorter lifetime than the static lifetime. Therefore, the future can be used for as long as the program is running. Ensuring this lifetime is essential, as we cannot force programmers to wait for a task to finish. If the developer never waits for a task, the task could run for the