Finalizers etcetera
Malcolm Wallace
Malcolm.Wallace at cs.york.ac.uk
Fri Oct 11 10:50:47 EDT 2002
"Simon Peyton-Jones" <simonpj at microsoft.com> writes:
> | takeMVar# :: SynchVar# s elt -> State# s -> (# State# s, elt #)
> | putMVar# :: SynchVar# s elt -> State# s -> State# s
>
> Bad idea to look at the primops.
(a) It was the first mention of MVars that I found in the docs.
(b) I only really mentioned it because the type sigs are wrong.
> | readMVar :: MVar a -> IO a
> | This is a combination of takeMVar and putMVar; ie. it takes the
> | value from the MVar, puts it back, and also returns it.
> |
> | It specifically avoids describing the combination as atomic ...
>
> False. readMVar is completely described by
> readMVar m = do { v <- takeMVar m; putMVar m v; return v }
>
> If it gets pre-empted between the take and the put, no matter; anyone
> trying to take from that same MVar will block.
Doesn't it block if another thread manages to sneak a putMVar into
the middle? Maybe I should read your "Awkward Squad" paper to find
out if this matters.
Regards,
Malcolm
More information about the FFI
mailing list