[GHC] #10975: At program exit, finalizer runs while foreign function is running
#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 <stdio.h> int finalized = 0; void finalizer(int *a) { finalized = 1; puts("finalizer"); } void call(int *a) { int i; unsigned w = 0; puts("begin call"); for(i = 0; i < 100000000; i++) { if(finalized) puts("finalized"); w += i; } printf("end call: %u\n", w); } }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10975> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#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 Resolution: | 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: | -------------------------------------+------------------------------------- Comment (by osa1): FWIW, I don't know why but marking "call" function `unsafe` prevents this(by default foreign functions are marked `safe`). -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10975#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC