Proposal: stackless coroutines as low-level primitives
This proposal assumes the existence of #23367. ## Background At the time of writing, @andrewrk and @jacobly0 are [exploring the idea](https://github.com/ziglang/zig/tree/async-await-demo) of implementing async/await in userland, based on the new `Io` interface. This allows using different approaches to implement async, such as single-threaded blocking, thread pool blocking, or green threads / fibers. The latter approach is likely to become the preferred method, because it is fairly performant and conceptually simple. At this point it seems incredibly likely that this will become the path forward for async/await in Zig; it has a lot of advantages! However, stackful coroutines via green threads do have some flaws. One of the most significant is that they simply aren't supported on some targets, such as Wasm and SPIR-V. Wasm is a particularly interesting example, because using stackless async in Wasm can be desirable in order to integrate with the JavaScript event loop -- for instance, expensive work in Wasm ought to periodically yield to the browser to allow other work to happen. The only way we can really do that is through stackless coroutines, which require language-level support. **In general, stackless coroutines will have broader support than stackful coroutines, because all of the suspend/resume machinery is lowered by the compiler to synchronous constructs.** #6025 proposes re-introducing stackless coroutines, as in stage1, to the self-hosted compiler. **This propos
Posted by mlugg on Apr 3, 2025, 12:09 AM
Tags
Related issues
- Fake websites pretending to be legitimate websites in order to steal your passwords was considered a HUGE problem.
- 3.5 Flash was always too expensive for a "flash" model.
- I don't think the realistic alternative here was “hire a team for a month and get a better semantic conversion” For a rewrite of this si...
- I was hosting on a PC at home like 10 years ago.
- I live in walking distance of all these things, and the farthest I’ve gotten my kid to do things alone is to walk to and from school (a w...
- It was a long time ago, so I don't remember.
Raise real-world problems, find people facing the same issue, and discuss solutions.2,000 issues0 comments
pricing (E-commerce)
Fake websites pretending to be legitimate websites in order to steal your passwords was considered a HUGE problem.
3.5 Flash was always too expensive for a "flash" model.
I don't think the realistic alternative here was “hire a team for a month and get a better semantic conversion” For a rewrite of this si...
I was hosting on a PC at home like 10 years ago.
I live in walking distance of all these things, and the farthest I’ve gotten my kid to do things alone is to walk to and from school (a w...
It was a long time ago, so I don't remember.
I still like to buy my cheap and esoteric Chinese stuff from Amazon.
My local area used to be great to find old used woodworking tools for cheap.
Proposal: stackless coroutines as low-level primitives
This proposal assumes the existence of #23367. ## Background At the time of writing, @andrewrk and @jacobly0 are [exploring the idea](https://github.com/ziglang/zig/tree/async-await-demo) of implementing async/await in userland, based on the new `Io` interface. This allows using different approaches to implement async, such as single-threaded blocking, thread pool blocking, or green threads / fibers. The latter approach is likely to become the preferred method, because it is fairly performant and conceptually simple. At this point it seems incredibly likely that this will become the path forward for async/await in Zig; it has a lot of advantages! However, stackful coroutines via green threads do have some flaws. One of the most significant is that they simply aren't supported on some targets, such as Wasm and SPIR-V. Wasm is a particularly interesting example, because using stackless async in Wasm can be desirable in order to integrate with the JavaScript event loop -- for instance, expensive work in Wasm ought to periodically yield to the browser to allow other work to happen. The only way we can really do that is through stackless coroutines, which require language-level support. **In general, stackless coroutines will have broader support than stackful coroutines, because all of the suspend/resume machinery is lowered by the compiler to synchronous constructs.** #6025 proposes re-introducing stackless coroutines, as in stage1, to the self-hosted compiler. **This propos
Comments (0)
No comments yet. Start the discussion.