知识卡片
协作调度需要让出
异步任务可在其子 Future 返回 Pending 时让出工作线程。长计算或同步阻塞即使位于 async fn 内,仍会拖长这次 poll。厨房示例通过提前启动外部等待缩短关键路径。工程上应依赖显式同步维护顺序,并让阻塞工作使用合适的线程资源。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 2. Basic Async Rust 从操作步骤到执行任务 · 查看原书依据
OK, now the order makes sense: we are boiling the water, putting bread in the toaster, and then pouring milk, and as a result, we saved 6 seconds. However, the cause and effect is counterintuitive. Putting in an extra sleep function has reduced our overall time. This is because that extra sleep function allowed the async runtime to switch context to other tasks and execute
参考来源
- 位置:《Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)》第02章《Chapter 2. Basic Async Rust》,从操作步骤到执行任务(来源项目 book-source,extracted/Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)/_epub-src/OEBPS/ch02.html#id10)
- 结论依据:书中在先行分支加入异步等待,得以先启动水壶及烤面包机。
- 原始内容:OK, now the order makes sense: we are boiling the water, putting bread in the toaster, and then pouring milk, and as a result, we saved 6 seconds. However, the cause and effect is counterintuitive. Putting in an extra sleep function has reduced our overall time. This is because that extra sleep function allowed the async runtime to switch context to other tasks and execute