[Haskell-cafe] Misleading MVar documentation

Mitar mmitar at gmail.com
Sat Dec 25 05:18:43 CET 2010


Hi!

On Sat, Dec 25, 2010 at 2:32 AM, Edward Z. Yang <ezyang at mit.edu> wrote:
> In particular, we should explicitly note the race conditions
> for not just swapMVar but also readMVar, withMVar, modifyMVar_ and modifyMVar,

I am not sure if this are really race conditions? The point is that
readMVar, withMVar and others do not return until they can return the
value back and after that the value is the same as it was at the
beginning of the call. So if somebody manages to put the value in then
those functions wait that the value is removed.

Race condition would mean for me that some other thread could corrupt
the data. This is not the case here.

So I would argue that it would be better to write that those function
can block. Not that there are race-conditions. Race-conditions (for
me) imply that invariants can change based on some other thread, here
they hold, when/if the function returns.

This is why I proposed tryReadMVar and tryModifyMVar here:

http://hackage.haskell.org/trac/ghc/ticket/4535


Mitar



More information about the Haskell-Cafe mailing list