[GHC] #7745: sleep interrupted in foreign call with GHC later than 7.2

GHC cvs-ghc at haskell.org
Wed Mar 6 17:45:57 CET 2013


#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



More information about the ghc-tickets mailing list