blob: 4fb9a4fff199273f7e085bf174212088ed2b38a2 (
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
|
-- Tests Foreign.Concurrent finalizers
import Text.Printf
import Foreign.Concurrent as Conc
import Foreign
import GHC.TopHandler
import Control.Concurrent
import System.Mem
-- This finalizer calls back into Haskell, so we can't use
-- the ordinary newForeignPtr.
foreign export ccall fin :: Ptr Int -> Ptr Int -> IO ()
foreign import ccall "fin" finptr :: Ptr Int -> Ptr Int -> IO ()
fin :: Ptr Int -> Ptr Int -> IO ()
fin envp ap = runIO $ do
env <- peek envp
a <- peek ap
printf "%d %d\n" env a
return ()
main = do
a <- new (55 :: Int)
env <- new (66 :: Int)
fp <- Conc.newForeignPtr a (finptr env a)
performGC
threadDelay 100000
|