Re: [Haskell-cafe] Why does sleep not work?
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 signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why does sleep not work?
I can confirm this behaviour, on: Linux 2.6.27-11-generic #1 SMP i686 GNU/Linux Difference in the RTS between non-working and working: (RTS way, rts_thr) (RTS way, rts) - George signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why does sleep not work?
The POSIX sleep function is defined as: sleep() makes the current process sleep until seconds seconds have elapsed or a signal arrives which is not ignored. Sounds like a signal is arriving that is interrupting the sleep. -Corey O'Connor 2009/2/9 John Ky newho...@gmail.com: Hi Peter, Source code: import System.IO import System.Posix main = do putStrLn Waiting for 5 seconds. sleep 5 -- doesn't sleep at all putStrLn Done. OS: Mac OS X 10.5 Compile command: ghc --threaded testsleep.hs If I remove --threaded, then it does sleep. Thanks, -John On Tue, Feb 10, 2009 at 8:59 AM, Peter Verswyvelen bugf...@gmail.com wrote: Hi John, Which sleep are you using? From which module? Can you show the full source with import statements? Cheers, Peter 2009/2/9 John Ky newho...@gmail.com 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. threadDelay 500 -- works putStrLn Done. main = do putStrLn Waiting for 5 seconds. sleep 5 -- doesn't sleep at all putStrLn Done. Anybody know what's happening? Thanks -John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why does sleep not work?
Not to say the issue shouldn't be tracked down, but shouldn't a more portable function be used anyway? untested example: maxBoundMicroSecInSec =(maxBound `div` 10^6) threadDelaySec :: Int - IO () threadDelaySec s | s maxBoundMicroSecInSec = threadDelay (maxBoundMicroSecInSec * 10^6) threadDelaySec (s - maxBoundMicroSecInSec) | otherwise = threadDelay (s * 10^6) On Tue, Feb 10, 2009 at 5:57 PM, Corey O'Connor coreyocon...@gmail.com wrote: The POSIX sleep function is defined as: sleep() makes the current process sleep until seconds seconds have elapsed or a signal arrives which is not ignored. Sounds like a signal is arriving that is interrupting the sleep. -Corey O'Connor 2009/2/9 John Ky newho...@gmail.com: Hi Peter, Source code: import System.IO import System.Posix main = do putStrLn Waiting for 5 seconds. sleep 5 -- doesn't sleep at all putStrLn Done. OS: Mac OS X 10.5 Compile command: ghc --threaded testsleep.hs If I remove --threaded, then it does sleep. Thanks, -John On Tue, Feb 10, 2009 at 8:59 AM, Peter Verswyvelen bugf...@gmail.com wrote: Hi John, Which sleep are you using? From which module? Can you show the full source with import statements? Cheers, Peter 2009/2/9 John Ky newho...@gmail.com 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. threadDelay 500 -- works putStrLn Done. main = do putStrLn Waiting for 5 seconds. sleep 5 -- doesn't sleep at all putStrLn Done. Anybody know what's happening? Thanks -John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why does sleep not work?
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. Manlio Perillo ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why does sleep not work?
On Tue, 2009-02-10 at 09:57 -0800, Corey O'Connor wrote: The POSIX sleep function is defined as: sleep() makes the current process sleep until seconds seconds have elapsed or a signal arrives which is not ignored. Sounds like a signal is arriving that is interrupting the sleep. -Corey O'Connor I tested this when testing the original code; sleep reports that the signal received is 5 (SIGTRAP). However, the following code does not work: import System.Posix main = do putStrLn Waiting for 5 seconds. print sigTRAP blockSignals $ addSignal sigTRAP emptySignalSet signal - sleep 5 print signal putStrLn Done. This, on the other (strange) hand, does: import System.Posix main = do putStrLn Waiting for 5 seconds. blockSignals fullSignalSet signal - sleep 5 print signal putStrLn Done. - George signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why does sleep not work?
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 signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why does sleep not work?
2009/2/10 George Pollard por...@porg.es: import System.Posix main = do putStrLn Waiting for 5 seconds. blockSignals $ addSignal sigVTALRM emptySignalSet sleep 5 putStrLn Done. Huh! Does the GHC runtime uses this signal? Perhaps for scheduling? Cheers, -Corey O'Connor ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why does sleep not work?
Also attached is a diff for strace between non-threaded and threaded. execve(./sleep, [./sleep], [/* 38 vars */]) = 0 execve(./sleep, [./sleep], [/* 38 vars */]) = 0 brk(0) = 0x83c2000 | brk(0) = 0x8ff access(/etc/ld.so.nohwcap, F_OK) = -1 ENOENT (No such access(/etc/ld.so.nohwcap, F_OK) = -1 ENOENT (No such mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONY | mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONY access(/etc/ld.so.preload, R_OK) = -1 ENOENT (No such access(/etc/ld.so.preload, R_OK) = -1 ENOENT (No such open(/etc/ld.so.cache, O_RDONLY) = 3 open(/etc/ld.so.cache, O_RDONLY) = 3 fstat64(3, {st_mode=S_IFREG|0644, st_size=68273, ...}) = 0 fstat64(3, {st_mode=S_IFREG|0644, st_size=68273, ...}) = 0 mmap2(NULL, 68273, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb801b000 | mmap2(NULL, 68273, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7f8d000 close(3)= 0 close(3) = 0 access(/etc/ld.so.nohwcap, F_OK) = -1 ENOENT (No such access(/etc/ld.so.nohwcap, F_OK) = -1 ENOENT (No such open(/lib/tls/i686/cmov/libutil.so.1, O_RDONLY) = 3 open(/lib/tls/i686/cmov/libutil.so.1, O_RDONLY) = 3 read(3, \177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\340\ read(3, \177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\340\ fstat64(3, {st_mode=S_IFREG|0644, st_size=9688, ...}) = 0 fstat64(3, {st_mode=S_IFREG|0644, st_size=9688, ...}) = 0 mmap2(NULL, 12424, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYW | mmap2(NULL, 12424, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYW mmap2(0xb8019000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP | mmap2(0xb7f8b000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP close(3)= 0 close(3) = 0 access(/etc/ld.so.nohwcap, F_OK) = -1 ENOENT (No such access(/etc/ld.so.nohwcap, F_OK) = -1 ENOENT (No such open(/lib/tls/i686/cmov/libdl.so.2, O_RDONLY) = 3 open(/lib/tls/i686/cmov/libdl.so.2, O_RDONLY) = 3 read(3, \177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0 \n\0 read(3, \177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0 \n\0 fstat64(3, {st_mode=S_IFREG|0644, st_size=9676, ...}) = 0 fstat64(3, {st_mode=S_IFREG|0644, st_size=9676, ...}) = 0 mmap2(NULL, 12408, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYW | mmap2(NULL, 12408, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYW mmap2(0xb8015000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP | mmap2(0xb7f87000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP close(3)= 0 close(3) = 0 access(/etc/ld.so.nohwcap, F_OK) = -1 ENOENT (No such access(/etc/ld.so.nohwcap, F_OK) = -1 ENOENT (No such open(/lib/tls/i686/cmov/libm.so.6, O_RDONLY) = 3 open(/lib/tls/i686/cmov/libm.so.6, O_RDONLY) = 3 read(3, \177elf\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\...@4\0\ read(3, \177elf\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\...@4\0\ fstat64(3, {st_mode=S_IFREG|0644, st_size=149332, ...}) = 0 fstat64(3, {st_mode=S_IFREG|0644, st_size=149332, ...}) = 0 mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONY | mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONY mmap2(NULL, 151680, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENY | mmap2(NULL, 151680, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENY mmap2(0xb801, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP | mmap2(0xb7f82000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP close(3)= 0 close(3) = 0 access(/etc/ld.so.nohwcap, F_OK) = -1 ENOENT (No such access(/etc/ld.so.nohwcap, F_OK) = -1 ENOENT (No such open(/usr/lib/libgmp.so.3, O_RDONLY) = 3 open(/usr/lib/libgmp.so.3, O_RDONLY) = 3 read(3, \177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\200\ read(3, \177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\200\ fstat64(3, {st_mode=S_IFREG|0644, st_size=284176, ...}) = 0 fstat64(3, {st_mode=S_IFREG|0644, st_size=284176, ...}) = 0 mmap2(NULL, 287052, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENY | mmap2(NULL, 287052, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENY mmap2(0xb7fea000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP | mmap2(0xb7f5c000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP close(3)= 0 close(3) = 0 access(/etc/ld.so.nohwcap, F_OK) = -1 ENOENT (No such access(/etc/ld.so.nohwcap, F_OK) = -1 ENOENT (No such open(/lib/tls/i686/cmov/librt.so.1, O_RDONLY) = 3 open(/lib/tls/i686/cmov/librt.so.1, O_RDONLY) = 3 read(3, \177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0`\31\ read(3,
Re: [Haskell-cafe] Why does sleep not work?
Corey O'Connor ha scritto: 2009/2/10 George Pollard por...@porg.es: import System.Posix main = do putStrLn Waiting for 5 seconds. blockSignals $ addSignal sigVTALRM emptySignalSet sleep 5 putStrLn Done. Huh! Does the GHC runtime uses this signal? Perhaps for scheduling? Right. It is used for scheduling, as far as I understand. So blocking it is a bad idea (unless you block it in a thread other than the main thread, IMO). Cheers, -Corey O'Connor Regards Manlio ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why does sleep not work?
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. Regards Manlio ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Why does sleep not work?
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. threadDelay 500 -- works putStrLn Done. main = do putStrLn Waiting for 5 seconds. sleep 5 -- doesn't sleep at all putStrLn Done. Anybody know what's happening? Thanks -John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why does sleep not work?
Hello John, Tuesday, February 10, 2009, 12:35:25 AM, you wrote: I am finding that using the sleep function doesn't sleep at all, whereas using threadDelay does: Anybody know what's happening? 1) this depends on your sleep definition 2) read threadDelay docs -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why does sleep not work?
Hi John, Which sleep are you using? From which module? Can you show the full source with import statements? Cheers, Peter 2009/2/9 John Ky newho...@gmail.com 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. threadDelay 500 -- works putStrLn Done. main = do putStrLn Waiting for 5 seconds. sleep 5 -- doesn't sleep at all putStrLn Done. Anybody know what's happening? Thanks -John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why does sleep not work?
Hi Peter, Source code: import System.IO import System.Posix main = do putStrLn Waiting for 5 seconds. sleep 5 -- doesn't sleep at all putStrLn Done. OS: Mac OS X 10.5 Compile command: ghc --threaded testsleep.hs If I remove --threaded, then it does sleep. Thanks, -John On Tue, Feb 10, 2009 at 8:59 AM, Peter Verswyvelen bugf...@gmail.comwrote: Hi John, Which sleep are you using? From which module? Can you show the full source with import statements? Cheers, Peter 2009/2/9 John Ky newho...@gmail.com 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. threadDelay 500 -- works putStrLn Done. main = do putStrLn Waiting for 5 seconds. sleep 5 -- doesn't sleep at all putStrLn Done. Anybody know what's happening? Thanks -John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe