← 返回起始笔记位置

知识卡片

普通读书笔记卡 · 10877.a.1.b.1 · 生成模型:未记录

作用域线程可借局部数据

理解等级:中级

thread::scope 把子线程的生存范围限制在一次作用域调用里。子线程可经 move 闭包接收局部缓冲区的独占切片。scope 退出前等它们结束,因此调用后可重新借用整图编码;访问不越过被借对象的有效期间。

关联阅读:[[不重叠切片并行写]]。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)》第01章《A Tour of Rust》|让线程在作用域内独占各自的带区,来源项目 `book-source`,`extracted/Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)/_epub-src/OEBPS/ch01.xhtml#a-concurrent-mandelbrot-program` - 结论依据:原文以 scope 等待子线程解释其为何能安全借用局部像素。 - 原始内容:The std::thread::scope function waits for all such threads to finish execution before returning itself. This behavior allows Rust to be sure that such