by papsosouid · 13y ago · 0 comments
(EDIT: hint your runtime can't, because the kernel doesn't provide a way to do that. I guess I should be more explicit).
Doesn't this make it harder to reason about cases where multiple userland threads need to mutate the same state? You can't tell by inspection whether the function you're calling is going to yield somewhere deep inside.
With single threaded callback style you know your thread is the only thing that is executing and won't be interrupted. (Sure, other code can run between now and when your callback is invoked, but in practice I find that to be pretty easy to deal with.)
Most languages make it very hard to reason about state in general. Haskell provides STM, so ensuring correct access to shared state is as simple as using an MVar. I absolutely agree that this is an important part of languages making concurrency a priority, they can't just add green threads and pretend that is good enough.
What you are saying is, you're a client of someone else's nonblocking event loop. So all the classical stuff regarding nonblock io loops apply.
E.g: http://talkingcode.co.uk/2008/12/02/haskell-gtk-and-multi-th...
But substitute Gtk for Qt, or anything where you're the sucker dealing with an external concurrency model or event loop.
Hilariously, they end up having the same debate we are here, just in Haskell.
Seriously, there's no pixie dust for this.
I have no idea why you are talking about pixie dust. My point was that explicitly using event loops instead of abstracting it into a green thread library is dumb, and we need to start having higher expectations from languages rather than accepting backwards shit like node. Not "green threads are magic".