Question about withMVar

Harendra Kumar <[email protected]> Sun, 18 Jul 2021 19:19:24 +0530
Newsgroups gmane.comp.lang.haskell.libraries
Message-ID <CAPW+kkY5JBZiV2+Z5StqL+gjv1xJMT92t_A-=4Up0F4mSB-tzg@mail.gmail.com>
The documentation of withMVar (in Control.Concurrent.MVar module of base
package) says:

{-|  'withMVar' is an exception-safe wrapper for operating on the
contents  of an 'MVar'.  This operation is exception-safe: it will
replace the  original contents of the 'MVar' if an exception is raised
(see  "Control.Exception").  However, it is only atomic if there are
no  other producers for this 'MVar'.-}withMVar :: MVar a -> (a -> IO
b) -> IO bwithMVar m io =  mask $ \restore -> do    a <- takeMVar m
b <- restore (io a) `onException` putMVar m a    putMVar m a    return
b

Can someone shed some light on what is meant by the statement -
"However, it is only atomic if there are no other producers for this 'MVar'."?

I hope this is the right mailing list for this question.

Thanks,
Harendra

_______________________________________________
Libraries mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries