I share the author's enthusiasm for coroutines. They're nice abstractions for all sorts of state-machine-like code and for concurrency (without parallelism).
> You could allocate a piece of memory for a coroutine stack; let the coroutines on it push and pop stack frames like ordinary function calls; and have a special ‘yield’ function that swaps out the stack pointer and switches over to executing on another stack. In fact, that’s not a bad way to add coroutines to a language that doesn’t already have them, because it doesn’t need the compiler to have any special knowledge of what’s going on. You could add coroutines to C in this way if you wanted to, and the approach would have several advantages over my preprocessor system.
In C minicoro is a nice library that provides just that: https://github.com/edubart/minicoro
In Zig there's zigcoro: https://github.com/rsepassi/zigcoro
Another source I found enlightening on coroutines is "Coroutines in Lua": https://www.lua.org/doc/jucs04.pdf
Lua's stackful coroutines are awesome! The Lua C API even allows to pass a continuation function when calling a Lua function from C, so you can yield across the C-call boundary (e.g. a Lua function, calling a C function, calling a Lua function that yields). See also https://www.lua.org/manual/5.2/manual.html#4.7
I'd add that while I was already familiar with coroutines from a few different contexts and languages, I found this particular framing of them -- especially seeing them contrasted side by side with a state-machine -- enlightening and novel.
We implemented a low-power wireless sensing device on a microcontroller using asynchronous coroutines in C to replace eight state machines. It was a dream. Every operation process was clearly "linear" in readability while overlapping radio frequency hopping, sensor power-up/down sequencing, sense state, transmission, firmware update, etc. All while going into low-power mode until the next event to process.
> and for concurrency (without parallelism)
They are pretty good as a task abstraction with parallelism as well.