sleep interrupted in foreign call with GHC later than 7.2
Noticed investigating 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.)
Trac metadata
Trac field | Value |
---|---|
Version | 7.6.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |