Re:Mill: Go-style concurrency in C
by davidw on Friday May 01, 2015 @07:33AM
(#9470648)
How's it work under the hood?
[ Parent
| on HN ]
Re:Mill: Go-style concurrency in C
by mikepurvis on Friday May 01, 2015 @10:58AM
(#9471792)
Clever macro expansions: https://github.com/sustrik/mill/blob/c1c302f7edb3811d9098f7b...
And computed gotos, which just jumps to a pointer, which is a gcc extension. That's totally crazy, but sort of awesome.
Getcontext/setcontext has always allowed for coroutines in C. This just adds a sugar layer of nonblocking functions that allows a runtime layer to switch between contexts (coroutines), just like Go.
The ucontext stuff is nice but why was it deprecated?
It's generally not a problem on x86, but in my experience for other platforms, it gets messy quickly.
It would be nice if a replacement or a "de-deprecated" was around.
Re:Mill: Go-style concurrency in C
by Blackthorn on Friday May 01, 2015 @11:27AM
(#9472039)
That question has seriously bothered me too. OS threads are not a replacement as they are preemptive. The deprecation was way premature.
Re:Mill: Go-style concurrency in C
by tedunangst on Friday May 01, 2015 @05:52PM
(#9474759)
makecontext cannot be correctly represented by the C type system.
I'm not very good at C, but from my understanding this library uses longjmp functions which means it's cooperative multithreading rather than preemptive isn't it?
correct
Here's a short toy implementation of the same principle: http://250bpm.com/blog:48