Atomically read the contents of an
MVar. If the
MVar is
currently empty,
readMVar will wait until it is full.
readMVar is guaranteed to receive the next
putMVar.
readMVar is multiple-wakeup, so when multiple readers are
blocked on an
MVar, all of them are woken up at the same time.
Compatibility note: Prior to base 4.7,
readMVar was a
combination of
takeMVar and
putMVar. This mean that in
the presence of other threads attempting to
putMVar,
readMVar could block. Furthermore,
readMVar would not
receive the next
putMVar if there was already a pending thread
blocked on
takeMVar. The old behavior can be recovered by
implementing 'readMVar as follows:
readMVar :: MVar a -> IO a
readMVar m =
mask_ $ do
a <- takeMVar m
putMVar m a
return a