Repository navigation
docs(readme): spawn + co_await example; document .await() deadlock boundary - #90
Merged
Merged
Conversation
…undary The README's top example used xpp::fiber + .await(). Switch it to xpp::spawn + co_await — the idiomatic pairing for the poll-driven spawn executor, while .await() is the fiber pairing. Discovered while validating the example that .await() inside a spawned fn deadlocks on cross-task dependency cycles (nested park blocks the outer loop from re-checking its woken flag). Document the boundary in spawn.h and file todos/fiber-driven-spawn-await.md for a fiber-driven spawn that would make .await() universally safe.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
README 顶部示例原用
xpp::fiber+.await()。换成spawn时发现:spawn是poll 驱动的执行体,它的惯用等待是
co_await(或 C++11 的.then()),而.await()是 fiber 的等待方式。改动
fiber + .await()→spawn + co_await(channel 生产/消费,sum=210)spawn.h文档:补充.await()在 spawn fn 里的跨任务依赖循环死锁边界——嵌套 park 使外层
X_RUN_ONCE无法返回检查 woken,consumer 等生产、producer等消费即死锁;推荐
.then()/co_await(waker 驱动、无嵌套栈)todos/fiber-driven-spawn-await.md:记录根治方向——spawn 的 fn 跑在 fiber 里,.await()自动走xFiberYield(不嵌套 loop),让.await()在 spawn 里普遍可用关键发现
PromiseContext::park()已有 fiber 分支(xFiberYield),但 spawn 的 fn 跑在普通栈上,
.await()走同步阻塞 + 嵌套X_RUN_ONCE。两个 spawn 任务互相 await 时形成嵌套 park 环 → 死锁。timer/I/O 场景安全(回调不嵌套 park);依赖循环必死锁。
验证
co_await 版示例临时测试通过(
sum: 210,无死锁),临时文件已删除。