
#13439: ForeignPtr finalizers not searched for reachable objects? -------------------------------------+------------------------------------- Reporter: | Owner: (none) facundo.dominguez | Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 8.0.2 Resolution: | Keywords: ForeignPtr | finalizers Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by facundo.dominguez): The documentation of [http://hackage.haskell.org/package/base-4.9.1.0/docs /Foreign-ForeignPtr.html#v:touchForeignPtr touchForeignPtr] mentions that it can't be used in finalizers to keep the pointer alive. But the program fails the same if one replaces it with {{{ main = do rFinalized <- newIORef Set.empty forM_ [0..50000] $ \i -> do fp0 <- newForeignPtr nullPtr $ atomicModifyIORef' rFinalized (\s -> (Set.insert i s, ())) + mv <- newMVar fp0 newForeignPtr nullPtr $ do finalized <- atomicModifyIORef' rFinalized (\s -> (Set.delete i s, Set.member i s)) when finalized $ putStrLn "fp0 was prematurely finalized" - touchForeignPtr fp0 + void $ takeMVar mv performMajorGC threadDelay 1000000 }}} Which means that the references in finalizers are peculiar in some sense beyond the specifics of `touchForeignPtr`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13439#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler