
#10975: At program exit, finalizer runs while foreign function is running
-------------------------------------+-------------------------------------
Reporter: akio | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.10.1
Keywords: | Operating System: Linux
Architecture: x86_64 | Type of failure: Incorrect result
(amd64) | at runtime
Test Case: | Blocked By:
Blocking: | Related Tickets:
Differential Rev(s): | Wiki Page:
-------------------------------------+-------------------------------------
The following code prints "finalized", which means the finalizer runs
while the "call" function is still running.
Steps to reproduce:
{{{
% ghc finalizer.hs foreign.c -threaded
% ./finalizer
}}}
finalizer.hs:
{{{#!hs
import Control.Concurrent
import Control.Monad
import Foreign.C.Types
import Foreign.ForeignPtr
import Foreign.Ptr
main :: IO ()
main = do
_ <- forkIO $ do
fptr <- newForeignPtr finalizer nullPtr
forever $ withForeignPtr fptr call
threadDelay 1000000
foreign import ccall "&finalizer" finalizer :: FunPtr (Ptr CInt -> IO ())
foreign import ccall "call" call :: Ptr CInt -> IO ()
}}}
foreign.c
{{{#!c
#include