These are stackful coroutines, as opposed to stackless.<p>Stackful coroutines create a new stack for each coroutine thread and save and restore the appropriate registers when switching. Stackless coroutines are basically normal C functions that have been hacked to save their local variables between calls and use gotos (or, notoriously, a switch statement) to resume from where they last yielded. Both are very useful in their own way.<p>This is a great project and I'll be trying it out in my current work.
I love how simple and elegant is this to use:
<a href="https://github.com/tidwall/neco/blob/main/examples/echo-server.c">https://github.com/tidwall/neco/blob/main/examples/echo-serv...</a><p>I was going to actually implement an echo server for load balancer health checks with minimal memory usage, but never considered doing it in C but I might just use it! Thank you so much.
I like how your examples become progressively more comprehensive. What was your thinking going into this? How did you design this library? i think you wanted something this beautiful and perfect to exist, am i right? Or is it also an exercise to develop your own understanding? I wouldn't know where to begin with C gens/coroutines. Probably I would just fallback on kernel/sys calls to suspend and hack from there: yay my function is stopped; yay my code has been called again. Are you using setjmp/longjmp?
Can someone help elucidate why "It's a non-goal for Neco to provide a scalable multithreaded runtime, where the coroutine scheduler is shared among multiple cpu cores [...]" this library even makes sense then? When I use coroutines in Go it is invariably in order to make use of more CPU cores when extra performance needs to be extracted.
I’ve used libaco with a lot of success in the past (mixing uv, curl, and zlib in a way that made the zlib loop easier to manage (since it looked like a normal read, decompress loop with all context stack local).<p>Any notes about why I would try Neco in the future?
It's a little lower level than what you have, but you may find somethings interesting here: <a href="https://github.com/Keith-Cancel/Bunki">https://github.com/Keith-Cancel/Bunki</a>
These are cooperatively scheduled green threads...<p>I feel the word "coroutine" is slowly losing its original meaning, similar to what happened to "lambda".
Can someone explain how this works please? How does it prevent this from saturating the CPU?<p><pre><code> while (1) {
neco_sleep(NECO_SECOND*2);
printf("tock\n");
}</code></pre>