5 ms·
No. Go uses stackful coroutines. This is more like an implementation of async/await in C.
by autumnal 7y ago
No. Go uses stackful coroutines. This is more like an implementation of async/await in C.
- Ericson2314 7y agoThe catch is brutal. This looks like an implementation of goto in C.
- banachtarski 7y agoHow so? The decision between a stackful and a stackless coroutine is precisely that, a decision. The tradeoff is that storing all registers/stack variables and processor state before a yield and restoring it after a resume is a non-trivial cost. For some applications, that cost may not matter, but for others, it may be critical. Also, this is less like a goto, and more like a setjmp/longjmp.
- Ericson2314 7y agoA stack is an over approximation of the closure of the continuation. You want something to create a union of all the relevant local variables of each state. Doing this efficiently is non compositional and so requires language support.
- hnbroseph 7y agoaren't most control structures just sugar for goto?
- Ericson2314 7y agoHonestly I'm not sure how to define "control" when dealing with languages in the abstract and not just compilation to conventional machine code. Many control operators involve continuations with closures, and cannot be desugared to goto as such.
- bogomipz 7y agoInteresting, does the async/await pattern always imply stackless then? Might you or someone else have any resources you could share on stackless vs stackful coroutines?
- gpderetta 7y agokinda; using a keyword instead of library call for suspend is done primarily to constrain suspension to a single stack frame (i.e. the calling continuation is not first class, same as for return), hence it is used to enforce the stackless-ness.