Re:ProtoThreads: Lightweight, Stackless Threads in C
by xiaodai on Sunday September 22, 2019 @10:45PM
(#21045557)
is this like an implementation of Go in the C language?
[ Parent
| on HN ]
Re:ProtoThreads: Lightweight, Stackless Threads in C
by autumnal on Sunday September 22, 2019 @11:14PM
(#21045654)
No. Go uses stackful coroutines. This is more like an implementation of async/await in C.
Re:ProtoThreads: Lightweight, Stackless Threads in C
by bogomipz on Monday September 23, 2019 @02:02AM
(#21046305)
Interesting, 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?
Re:ProtoThreads: Lightweight, Stackless Threads in C
by gpderetta on Monday September 23, 2019 @03:24AM
(#21046647)
kinda; 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.
Re:ProtoThreads: Lightweight, Stackless Threads in C
by Ericson2314 on Sunday September 22, 2019 @11:25PM
(#21045704)
The catch is brutal. This looks like an implementation of goto in C.
Re:ProtoThreads: Lightweight, Stackless Threads in C
by banachtarski on Sunday September 22, 2019 @11:39PM
(#21045747)
How 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.
Re:ProtoThreads: Lightweight, Stackless Threads in C
by Ericson2314 on Monday September 23, 2019 @02:27PM
(#21051914)
A 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.
Re:ProtoThreads: Lightweight, Stackless Threads in C
by hnbroseph on Monday September 23, 2019 @01:18AM
(#21046110)
aren't most control structures just sugar for goto?
Re:ProtoThreads: Lightweight, Stackless Threads in C
by Ericson2314 on Monday September 23, 2019 @03:07PM
(#21052388)
Honestly 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.