1 {-# OPTIONS -fglasgow-exts #-}
9 choose :: a -> a -> IO a
12 answer <- newEmptyMVar
13 a_id <- myForkIO (a `seq` takeMVar ready >> putMVar answer a)
14 b_id <- myForkIO (b `seq` takeMVar ready >> putMVar answer b)
20 -- We need to catch the exception raised by killThread and ignore it.
21 -- Otherwise the default handler will exit the program when this
22 -- exception is raised in any thread.
24 myForkIO :: IO () -> IO ThreadId
25 myForkIO io = forkIO (Exception.catch io (\e -> return ()))
30 test1 <- choose big small
31 test2 <- choose small big