知识卡片
协程暂停保存状态
协程保存恢复所需的状态,将执行分成多次 resume。一轮恢复可产生中间值并让出,也可以完成。协作式切换适合细分可暂停的工作,阻塞系统调用或长计算仍会占住当前驱动线程。关联 [[协作调度需要让出]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
- · 协作式协程与线程
原书出处 · 1 处
- Chapter 5. Coroutines 协作式协程与线程 · 查看原书依据
Let’s compare a coroutine to a subroutine. After a subroutine starts, it executes from the start to the end, and any particular instance of a subroutine returns just one time. A coroutine is different, as it can exit in multiple ways. It can finish like a subroutine, but it can also exit by calling another coroutine (called yielding) and then returning later to the same
参考来源
- 位置:《Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)》第05章《Chapter 5. Coroutines》,协作式协程与线程(来源项目 book-source,extracted/Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)/_epub-src/OEBPS/ch05.html#id30)
- 结论依据:原书对照普通子程序和协程,说明协程能从上一次让出的地方继续。
- 原始内容:Let’s compare a coroutine to a subroutine. After a subroutine starts, it executes from the start to the end, and any particular instance of a subroutine returns just one time. A coroutine is different, as it can exit in multiple ways. It can finish like a subroutine, but it can also exit by calling another coroutine (called yielding) and then returning later to the same