3 ms·
Someone needs to make a tiny C lib that contains just the stack switching stuff (basically whatever is used as a substitute for ucontext), that the various coro
by jkarneges 11y ago
Someone needs to make a tiny C lib that contains just the stack switching stuff (basically whatever is used as a substitute for ucontext), that the various coroutine libs can share. I like all these coroutine libs (libtask, lthread, libmill, etc), but it makes me uneasy to have non-portable assembly code lying about that might go unmaintained.
- BlackFingolfin 11y agoI didn't see any assembler code in libmill, nor does it use ucontext. Not sure what you are talking about here?
- jkarneges 11y agoAh, I forgot libmill uses setjmp/longjmp. I'm not sure how that really works for coroutines though since you still need to deal with stack allocations. So replace "non-portable assembly" with "possibly non-portable C hacks". I haven't gotten around to digging deep in the code yet though. If libmill's approach is future-proof then that'd be pretty awesome.
- rumcajz 11y agoIt's a hack, but one that's relatively benign: allocate stack using malloc, move sp using variable-sized array.
- versteegen 11y agoThere are oh so many libraries for that: https://github.com/baruch/libwire/wiki/Other-coroutine-libraries https://github.com/baruch/libwire/wiki/Other-coroutine-libra... And if you don't like any of those, my next choice would be to use the implementation from Luajit 1.x and 2.x, called Coco but not packaged into a separate library: http://coco.luajit.org/portability.html http://coco.luajit.org/portability.html
- jkarneges 11y agoCool! I wasn't aware of those low level libs. Now I should submit a patch to lthread to use fcontext. >:)