GNU bug report logs -
#19581
'sleep' return value is incorrectly rounded
Previous Next
Full log
Message #8 received at 19581 <at> debbugs.gnu.org (full text, mbox):
Hi :)
On Tue 13 Jan 2015 13:58, ludo <at> gnu.org (Ludovic Courtès) writes:
> I just noticed that ‘sleep’ essentially always rounds down its return
> value, which makes it unreliable, as in this example:
>
> $ time guile -c '(sigaction SIGINT +) (call-with-new-thread (lambda () (let loop () (kill (getpid) SIGINT) (loop)))) (let loop ((n 3)) (when (> n 0) (loop (sleep (pk "s" n)))))'
>
> ;;; ("s" 3)
>
> ;;; ("s" 2)
>
> ;;; ("s" 1)
>
> real 0m0.039s
> user 0m0.052s
> sys 0m0.017s
>
> Here ‘loop’ is meant to assure we sleep for roughly 3 seconds, but
> because of the incorrect rounding, we end up not sleeping at all.
Hummmmmmmmmm.
I don't think we can change anything in 2.0. Right?
In master, how about (1) we allow sleep to take any real number, in
seconds; (2) sleep returns an inexact real number. Then we can
deprecate usleep and "standardize" on sleeping in units of seconds.
Internally we refactor scm_std_usleep/* to take a 64-bit double for the
number of seconds to sleep and return a double for the time remaining.
WDYT?
Andy
This bug report was last modified 8 years and 353 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.