by xyzzy123 · 13y ago · 0 comments
It's like a deal with the devil for performance... I guess I am disagreeing with the grandparent post. Maybe in Haskell it works (or is free), but C/C++, it works, but you can see you're paying for it.
Well put. You usually pay for it. Not familiar with Haskell too much to tell. It might provide the solution to trick the devil. The devil usually wins the bets though ;-)
(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.