Commit 73c48a99 authored by simonm's avatar simonm
Browse files

[project @ 1999-05-07 11:16:37 by simonm]

Ignore exceptions in the spawned threads.
parent 65c6e0da
...@@ -3,19 +3,27 @@ ...@@ -3,19 +3,27 @@
module Main where module Main where
import Concurrent import Concurrent
import Exception
import IOExts import IOExts
choose :: a -> a -> IO a choose :: a -> a -> IO a
choose a b = do choose a b = do
ready <- newMVar () ready <- newMVar ()
answer <- newEmptyMVar answer <- newEmptyMVar
a_id <- forkIO (a `seq` takeMVar ready >> putMVar answer a) a_id <- myForkIO (a `seq` takeMVar ready >> putMVar answer a)
b_id <- forkIO (b `seq` takeMVar ready >> putMVar answer b) b_id <- myForkIO (b `seq` takeMVar ready >> putMVar answer b)
it <- takeMVar answer it <- takeMVar answer
killThread a_id killThread a_id
killThread b_id killThread b_id
return it return it
-- We need to catch the exception raised by killThread and ignore it.
-- Otherwise the default handler will exit the program when this
-- exception is raised in any thread.
myForkIO :: IO () -> IO ThreadId
myForkIO io = forkIO (catchAllIO io (\e -> return ()))
main = do main = do
let big = sum [1..] let big = sum [1..]
small = sum [1..42] small = sum [1..42]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment