blob: 15b2e64a00a14b3a1458b09e9965eec7dee91352 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
import Control.Exception
import Control.Concurrent
import Text.Printf
import Prelude hiding(catch)
-- Test combinations of nesting mask/uninterruptibleMask with
-- forkIO/forkIOUnmask
main = do
m <- newEmptyMVar
t1 <- mask_ $ forkIO $ do
takeMVar m `catch` \e -> do stat 1 MaskedInterruptible
print (e::SomeException)
throwIO e
killThread t1
t2 <- uninterruptibleMask_ $ forkIO $ do
takeMVar m `catch` \e -> do stat 2 MaskedUninterruptible
print (e::SomeException)
throwIO e
killThread t2
t3 <- mask_ $ forkIOUnmasked $ do stat 3 Unmasked; putMVar m ()
takeMVar m
t4 <- uninterruptibleMask_ $ forkIOUnmasked $ do stat 4 Unmasked; putMVar m ()
takeMVar m
stat :: Int -> MaskingState -> IO ()
stat n m = do
s <- getMaskingState
if (s /= m)
then error (printf "%2d: %s\n" n (show s))
else return ()
|