diff options
Diffstat (limited to 'lifted-concurrent/test/TestThreads.hs')
-rw-r--r-- | lifted-concurrent/test/TestThreads.hs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lifted-concurrent/test/TestThreads.hs b/lifted-concurrent/test/TestThreads.hs new file mode 100644 index 00000000..8360badb --- /dev/null +++ b/lifted-concurrent/test/TestThreads.hs | |||
@@ -0,0 +1,21 @@ | |||
1 | import Control.Monad | ||
2 | import Control.Exception (throwIO) | ||
3 | |||
4 | import Control.Concurrent.ThreadUtil | ||
5 | import DebugUtil | ||
6 | |||
7 | main = do | ||
8 | mvars <- sequence $ replicate 200 $ newEmptyMVar | ||
9 | threads <- forM mvars $ forkIO . join . takeMVar | ||
10 | let (normalquits,mvars1) = splitAt 20 mvars | ||
11 | mapM_ (`putMVar` return ()) normalquits | ||
12 | let (exceptionquits,mvars2) = splitAt 20 mvars1 | ||
13 | mapM_ (`putMVar` throwIO (userError "oops")) exceptionquits | ||
14 | let (throwtoexceptions,threads1) = splitAt 20 $ drop 40 threads | ||
15 | mapM_ (`throwTo` userError "throwTo-oops") throwtoexceptions | ||
16 | let (killed,threads2) = splitAt 20 threads1 | ||
17 | mapM_ killThread killed | ||
18 | threadDelay 1000000 | ||
19 | report <- threadReport True | ||
20 | sequence_ $ zipWith (\n s -> putStrLn $ unwords [show n,s]) [1..] $ lines report | ||
21 | return () | ||