[project @ 1999-06-14 11:17:12 by simonmar]
[ghc-hetmet.git] / ghc / tests / concurrent / should_run / conc012.hs
1 module Main where
2
3 import Concurrent
4 import Exception
5 import GlaExts
6
7 data Result = Died Exception | Finished
8
9 -- Test stack overflow catching.  Should print "Died: stack overflow".
10
11 stackoverflow :: Int -> Int
12 stackoverflow 0 = 1
13 stackoverflow n = n + stackoverflow n
14
15 main = do
16   let x = stackoverflow 1
17   result <- newEmptyMVar 
18   forkIO (catchAllIO (x `seq` putMVar result Finished) 
19                      (\e -> putMVar result (Died e)))
20   res <- takeMVar result
21   case res of
22         Died e -> putStr ("Died: " ++ show e ++ "\n")
23         Finished -> putStr "Ok.\n"