[Haskell-cafe] Why does sleep not work?
George Pollard
porges at porg.es
Tue Feb 10 18:36:49 EST 2009
On Wed, 2009-02-11 at 00:05 +0100, Manlio Perillo wrote:
> John Ky ha scritto:
> > Hi Haskell Cafe,
> >
> > I wrote very short program to sleep for 5 seconds compiled with the
> > -threaded option in ghc on the Mac OS X 1.5.
> >
> > I am finding that using the sleep function doesn't sleep at all, whereas
> > using threadDelay does:
> >
> > [...]
> > main = do
> > putStrLn "Waiting for 5 seconds."
> > sleep 5 -- doesn't sleep at all
> > putStrLn "Done."
> >
> > Anybody know what's happening?
> >
>
> Here is a syscal trace, on Linux:
> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=1332#a1332
>
>
> The interesting part:
> write(1, "Waiting for 5 seconds.\n"..., 23) = 23
> rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
> rt_sigaction(SIGCHLD, NULL, {SIG_DFL}, 8) = 0
> rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
> nanosleep({5, 0}, 0xbf85f5cc) = ? ERESTART_RESTARTBLOCK (To be
> restarted)
> --- SIGVTALRM (Virtual timer expired) @ 0 (0) ---
> sigreturn() = ? (mask now [])
> write(1, "5\n"..., 2) = 2
>
>
> 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
-------------- 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/fd631dae/attachment.bin
More information about the Haskell-Cafe
mailing list