Or better yet, program in Go ;)
Or better yet, program in Go ;)
I have no argument in principle for the idea that you should restructure your whole program's control flow with transparent cooperative scheduling to attempt to get the best of both worlds of straight-line coding and efficient scheduling, except that it feels to me like you're kind of not really even writing C code anymore at that point. This might be irrational of me.
In the meantime, if you're not going to adopt an exotic thread scheduling library, I think events are the way to go. POSIX threads don't make much sense to me.
Maintaining any kind of long-term state for the functions which the event loop calls can be trickier than it needs to be, since they need to quickly return and can't leave anything on their stack.
GHC's thread system and IO manager is implemented in terms of epoll, for example.
And when I write performance-oriented C code, I use events, because great tight resource control is facilitated by that style.