3 ms·
How's it work under the hood?
by davidw 12y ago
How's it work under the hood?
- smegel 12y agoGetcontext/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.
- octetta 12y agoThe 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.
- Blackthorn 12y agoThat question has seriously bothered me too. OS threads are not a replacement as they are preemptive. The deprecation was way premature.
- tedunangst 12y agomakecontext cannot be correctly represented by the C type system.
- frankerz 12y agoI'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?
- rumcajz 12y agocorrect
- rumcajz 12y agoHere's a short toy implementation of the same principle: http://250bpm.com/blog:48 http://250bpm.com/blog:48
- mikepurvis 12y agoClever macro expansions: https://github.com/sustrik/mill/blob/c1c302f7edb3811d9098f7b2aff202ddb22df1ab/mill.h#L93 https://github.com/sustrik/mill/blob/c1c302f7edb3811d9098f7b...
- a1k0n 12y agoAnd computed gotos, which just jumps to a pointer, which is a gcc extension. That's totally crazy, but sort of awesome.