summaryrefslogtreecommitdiff
path: root/testsuite/tests/ffi/should_run/T7170.hs
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/ffi/should_run/T7170.hs')
-rw-r--r--testsuite/tests/ffi/should_run/T7170.hs21
1 files changed, 21 insertions, 0 deletions
diff --git a/testsuite/tests/ffi/should_run/T7170.hs b/testsuite/tests/ffi/should_run/T7170.hs
new file mode 100644
index 0000000000..4dbf65a157
--- /dev/null
+++ b/testsuite/tests/ffi/should_run/T7170.hs
@@ -0,0 +1,21 @@
+{-# LANGUAGE ForeignFunctionInterface #-}
+import Control.Concurrent
+import Control.Exception (bracket)
+import Foreign.Ptr (Ptr, intPtrToPtr, ptrToIntPtr)
+import Foreign.ForeignPtr (ForeignPtr)
+import qualified Foreign.Concurrent as FC
+import qualified Foreign.ForeignPtr as FP
+
+testForeignPtr_Concurrent :: Ptr a -> IO (ForeignPtr a)
+testForeignPtr_Concurrent ptr = FC.newForeignPtr ptr (fin ptr)
+
+fin :: Ptr a -> IO ()
+fin ptr = putStrLn $ "finalizing " ++ show (fromIntegral (ptrToIntPtr ptr) :: Int)
+
+main :: IO ()
+main = do
+ mv <- newEmptyMVar
+ bracket (testForeignPtr_Concurrent $ intPtrToPtr 1)
+ FP.finalizeForeignPtr $ \_ ->
+ -- hang, so the thread and foreign pointer get GCed
+ takeMVar mv