[GHC] #7745: sleep interrupted in foreign call with GHC later than 7.2
#7745: sleep interrupted in foreign call with GHC later than 7.2 ------------------------------+--------------------------------------------- Reporter: daniel.is.fischer | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.6.1 | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: None/Unknown | Blockedby: Blocking: | Related: ------------------------------+--------------------------------------------- Noticed investigating [http://stackoverflow.com/questions/15226806/importing-c-delay-function- into-haskell-using-ffi this question]: With GHC `>= 7.4`, a `sleep` in a foreign call is interrupted immediately, GHC `< 7.4` let it sleep with the non-threaded runtime. Test case: {{{ #include <unistd.h> #include <stdio.h> unsigned delay(unsigned howLong) { unsigned s = sleep(howLong); printf("Done sleeping about %u s.\n", howLong); return s; } }}} Calling code: {{{ {-# LANGUAGE ForeignFunctionInterface #-} module Main (main) where import Foreign.C.Types foreign import ccall unsafe "delay" c_delay :: CUInt -> IO CUInt hdelay :: Int -> IO Int hdelay howlong = fromIntegral `fmap` c_delay (fromIntegral howlong) main = do putStrLn "Delaying" n <- hdelay 2 putStrLn $ "sleep returned " ++ show n }}} compiled with `ghc cdelay.hs wdelay.c` With GHC `>= 7.4`, `sleep` returns 2, and the programme finishes instantly. With GHC `< 7.4`, it successfully `sleep`s 2 seconds. I think that is not the desired behaviour. (With the threaded runtime, also older GHCs interrupt the `sleep`, but I think that may be intended.) -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7745> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#7745: sleep interrupted in foreign call with GHC later than 7.2 ----------------------------------+----------------------------------------- Reporter: daniel.is.fischer | Owner: Type: bug | Status: closed Priority: normal | Component: Compiler Version: 7.6.1 | Resolution: invalid Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: None/Unknown Blockedby: | Blocking: Related: | ----------------------------------+----------------------------------------- Changes (by ezyang): * status: new => closed * resolution: => invalid Comment: Your C code needs to handle SIGVTALRMs: {{{ nanosleep({2, 0}, {1, 995333267}) = ? ERESTART_RESTARTBLOCK (To be restarted) --- SIGVTALRM (Virtual timer expired) @ 0 (0) -- rt_sigreturn(0x1a) = -1 EINTR (Interrupted system call) }}} See also http://hackage.haskell.org/trac/ghc/wiki/Commentary/Rts/Signals -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7745#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC