[Haskell-cafe] Re: Asynchronous exception wormholes kill modularity

Bertram Felgenhauer bertram.felgenhauer at googlemail.com
Fri Apr 9 04:40:04 EDT 2010

Simon Marlow wrote:
> but they are needlessly complicated, in my opinion.  This offers the
> same functionality:
> mask :: ((IO a -> IO a) -> IO b) -> IO b
> mask io = do
>   b <- blocked
>   if b
>      then io id
>      else block $ io unblock

How does forkIO fit into the picture? That's one point where reasonable
code may want to unblock all exceptions unconditionally - for example to
allow the thread to be killed later.

    timeout t io = block $ do
        result <- newEmptyMVar
        tid <- forkIO $ unblock (io >>= putMVar result)
        threadDelay t `onException` killThread tid
        killThread tid
        tryTakeMVar result



More information about the Haskell-Cafe mailing list