Stackswap coroutines, neither stackful nor stackless
cofault.com
cofault.com
It would be great if the post included some suggested applications. I also found the benchmark graphs hard to read. A table with numbers would have been easier.
This is mostly of interest for very low memory systems, right? Otherwise it's easier to use conventional stackful coroutines or multitasking. Even the traditional tiny Forth multitaskers were stackful, I think.
In this environment the stack size of a coroutine should be about constant at the yield points, or else maybe you want to allocate the copy buffers on the heap? Also if the coroutines don't persist, you may need a way to free their storage. Alternatively, maybe you can GC the memory buffer once in a while, by collapsing out unused parts.
> "I also found the benchmark graphs hard to read. A table with numbers would have been easier."
This is my only complaint too, very interesting stuff.I had been envisioning copying the stack images to a memory array rather than using alloca, though maybe alloca would also work. I see in your benchmarks you tested this on a quite large system. I had imagined something much smaller, like an Arduino. I might try porting your benchmark to GHC, Elixir, and maybe even Forth.
Pointers into the stack get invalidated on context switch which kills most of the advantage of a stackful coroutine. Alloc+copy per context switch makes context switching more expensive which kills the rest of the advantage. It does seem simpler than dealing with unknown size stacks though.
I see the attraction of allocating the stack on first yield but not on every yield.