[Haskell-cafe] Why does sleep not work?
George Pollard
porges at porg.es
Wed Feb 11 03:24:53 EST 2009
On Wed, 2009-02-11 at 01:50 +0100, Manlio Perillo wrote:
> George Pollard ha scritto:
> > [...]
> >
> >> So, it seems nanosleep get interruped by a signal.
> >
> > This works:
> >
> >> import System.Posix
> >>
> >> main = do
> >> putStrLn "Waiting for 5 seconds."
> >> blockSignals $ addSignal sigVTALRM emptySignalSet
> >> sleep 5
> >> putStrLn "Done."
> >>
> > So (see my earlier email) `sleep` is lying about what interrupts it :)
> >
> > - George
>
>
> A possibly better solution is:
>
> sleep' :: Int -> IO Int
> sleep' n = do
> n' <- sleep n
> if n' == 0 then return 0 else sleep' n'
>
>
> From the trace, I see that nanosleep is being called 17 times here.
>
> Another solution is to set RTS flag:
> ./bug_sleep +RTS -V0 -RTS
>
>
> What strange is that the timer is created in non threaded RTS, too, but
> sleep is interrupted only with the threaded RTS.
>
> This may be caused by an "incorrect" execution of a foreign function
> marked safe.
I just realized that for some reason I thought that `sleep` reported
the signal that interrupted it... contrary to the documentation... as
such, several of my replies to this thread may read as non-sequiturs :P
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090211/b010c2a1/attachment.bin
More information about the Haskell-Cafe
mailing list