News for hackers. Stuff that matters.
Re:Go-style concurrency in C by jkarneges on Wednesday November 18, 2015 @03:26AM (#10586620)
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.
Re:Go-style concurrency in C by versteegen on Wednesday November 18, 2015 @04:49AM (#10586847)
There are oh so many libraries for that:

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

Re:Go-style concurrency in C by jkarneges on Wednesday November 18, 2015 @03:53PM (#10590665)
Cool! I wasn't aware of those low level libs. Now I should submit a patch to lthread to use fcontext. >:)
Re:Go-style concurrency in C by BlackFingolfin on Wednesday November 18, 2015 @03:52AM (#10586678)
I didn't see any assembler code in libmill, nor does it use ucontext. Not sure what you are talking about here?
Re:Go-style concurrency in C by jkarneges on Wednesday November 18, 2015 @04:08AM (#10586728)
Ah, 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.
Re:Go-style concurrency in C by rumcajz on Wednesday November 18, 2015 @04:35AM (#10586804)
It's a hack, but one that's relatively benign: allocate stack using malloc, move sp using variable-sized array.