[Haskell-cafe] readMVar and the devils

Andy Moran moran at galois.com
Fri Jul 2 09:59:21 EDT 2004



> at a guess the magic take put is:
>
> block ( do
> a <- takeMVar x
> putMVar x a
> )
> return a

This doesn't prevent the race condition Conor mentioned. It only prevents
the thread executing the above code from being interrupted by an
asynchronous exception (i.e., Control-C, or another thread killing this
one). The only way to prevents race conditions is through discipline (take
then put is one example). A good way to enforce this discipline is to use
withX-style combinators, and treat the put/take group of operations as
primitives.

A



More information about the Haskell-Cafe mailing list