3cd3673a108b8472f52e9500e3c10906793826bb
[ghc-hetmet.git] / ghc / tests / lib / should_run / stableptr002.hs
1 module Main where
2
3 import Stable
4
5 -- Testing callbacks: the initial haskell thread calls out to C with
6 -- the address of a Haskell callback.  The C function runs the callback
7 -- (in a new thread) and returns.
8
9 -- The stable pointer operation 'performIO' does the job of calling
10 -- the callback for us.
11
12 -- for an extra stressful test, the callback also does an explicit GC
13 -- to make sure that the original thread saved away its state
14 -- properly.
15
16 main = do
17   io <- makeStablePtr hello
18   _ccall_GC_ performIO io
19   putStr "finished"
20
21 hello :: IO ()
22 hello  = do
23   _ccall_GC_ performGC
24   putStr "hello world!\n"