[Haskell-beginners] STM and IO
Quentin Moser
quentin.moser at unifr.ch
Thu Apr 9 06:16:54 EDT 2009
On Thu, 9 Apr 2009 12:03:03 +0200
Quentin Moser <quentin.moser at unifr.ch> wrote:
> Here's an example inspired by the documentation of Control.Concurrent:
>
> > import Control.Concurrent
> > import Control.Exception (finally)
> >
> > myFork :: IO () -> IO (MVar ())
> > myFork a = do v <- newEmptyMVar
> > a `finally` (putMVar v ())
> >
> > myWait :: MVar () -> IO ()
> > myWait = readMVar
Oops, my code is completely messed up. Here's a correct version:
> myFork a = do v <- newEmptyMVar
> forkIO $ a `finally` putMVar v ()
> return v
> myWait = readMVar >> return ()
More information about the Beginners
mailing list