blob: 4101212ad11178ada0d20eb4fd7bb509b9331eee (
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
|
import Control.Concurrent
import Control.Exception
import Foreign
import System.IO (hFlush,stdout)
import Prelude hiding (catch)
-- !!! Try to get two threads into a knot depending on each other.
-- This should result in the main thread being sent a NonTermination
-- exception (in GHC 5.02, the program is terminated with "no threads
-- to run" instead).
main = do
Foreign.newStablePtr stdout
-- HACK, because when these two threads get blocked on each other,
-- there's nothing keeping stdout alive so it will get finalized.
-- SDM 12/3/2004
let a = last ([1..10000] ++ [b])
b = last ([2..10000] ++ [a])
-- we have to be careful to ensure that the strictness analyser
-- can't see that a and b are both bottom, otherwise the
-- simplifier will go to town here, resulting in something like
-- a = a and b = a.
forkIO (print a `catch` \NonTermination -> return ())
-- we need to catch in the child thread too, because it might
-- get sent the NonTermination exception first.
r <- Control.Exception.try (print b)
print (r :: Either NonTermination ())
|