ad4fc692f7d38ab9b3911a5307692c480a0d4a02
[ghc-hetmet.git] / ghc / tests / concurrent / should_run / conc015.hs
1 import Concurrent
2 import Exception
3
4 -- test blocking & unblocking of async exceptions.
5
6 -- the first exception "foo" should be caught by the "caught1" handler,
7 -- since async exceptions are blocked outside this handler.
8
9 -- the second exception "bar" should be caught by the outer "caught2" handler,
10 -- (i.e. this tests that async exceptions are properly unblocked after
11 -- being blocked).
12
13 main = do
14   main_thread <- myThreadId
15   m <- newEmptyMVar
16   m2 <- newEmptyMVar
17   forkIO (do takeMVar m
18              raiseInThread main_thread (ErrorCall "foo")
19              raiseInThread main_thread (ErrorCall "bar") 
20              putMVar m2 ()
21          )
22   ( do
23     blockAsyncExceptions (do
24         putMVar m ()
25         threadDelay 500000
26         (unblockAsyncExceptions (threadDelay 500000))
27                 `catchAllIO` (\e -> putStrLn ("caught1: " ++ show e))
28      )
29     takeMVar m2
30    )
31     `catchAllIO`
32     (\e -> putStrLn ("caught2: " ++ show e))