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