
On Fri, Mar 26, 2010 at 3:43 PM, Gregory Collins
Matthew Brecknell
writes: And is confirmed by a simple test (with GHC 6.10.4 on Linux):
import Prelude hiding(catch) import Control.Concurrent import Control.Exception
main = do chan <- newEmptyMVar done <- newEmptyMVar kill <- block $ forkIO $ do (takeMVar chan >>= putMVar done) `onException` putMVar done "Exception received during takeMVar" ...
Should this be "forkIO $ block" instead of "block $ forkIO"?
No. First of all note that forked threads inherit the blocked state of their parents: http://haskell.org/ghc/docs/latest/html/libraries/base-4.2.0.0/Control-Excep... The reason Matthew first blocks then calls forkIO is that he needs to install an exception handler for the forked thread: `onException` putMVar done "Exception received during takeMVar" If he does not call block or only later calls it in the forked thread a chance exists that an asynchronous exception is thrown to the forked thread before the exception handler is installed. regards, Bas