summaryrefslogtreecommitdiff
path: root/testsuite/tests/ghc-regress/concurrent/should_run/conc012.hs
blob: a2f139e401cb866950a56df00b3ac60ce7277bcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module Main where

import Control.Concurrent
import Control.Exception
--import GlaExts

data Result = Died SomeException | Finished

-- Test stack overflow catching.  Should print "Died: stack overflow".

stackoverflow :: Int -> Int
stackoverflow 0 = 1
stackoverflow n = n + stackoverflow n

main = do
  let x = stackoverflow 1
  result <- newEmptyMVar 
  forkIO $ Control.Exception.catch (x `seq` putMVar result Finished) $
		     \e -> putMVar result (Died e)
  res <- takeMVar result
  case res of
	Died e -> putStr ("Died: " ++ show e ++ "\n")
	Finished -> putStr "Ok.\n"