* bug#19581: 'sleep' return value is incorrectly rounded
@ 2015-01-13 12:58 Ludovic Courtès
2016-06-23 9:02 ` Andy Wingo
0 siblings, 1 reply; 3+ messages in thread
From: Ludovic Courtès @ 2015-01-13 12:58 UTC (permalink / raw)
To: 19581
I just noticed that ‘sleep’ essentially always rounds down its return
value, which makes it unreliable, as in this example:
--8<---------------cut here---------------start------------->8---
$ 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
--8<---------------cut here---------------end--------------->8---
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.
Ludo’.
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#19581: 'sleep' return value is incorrectly rounded
2015-01-13 12:58 bug#19581: 'sleep' return value is incorrectly rounded Ludovic Courtès
@ 2016-06-23 9:02 ` Andy Wingo
2016-06-23 13:09 ` Ludovic Courtès
0 siblings, 1 reply; 3+ messages in thread
From: Andy Wingo @ 2016-06-23 9:02 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: 19581
Hi :)
On Tue 13 Jan 2015 13:58, ludo@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
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#19581: 'sleep' return value is incorrectly rounded
2016-06-23 9:02 ` Andy Wingo
@ 2016-06-23 13:09 ` Ludovic Courtès
0 siblings, 0 replies; 3+ messages in thread
From: Ludovic Courtès @ 2016-06-23 13:09 UTC (permalink / raw)
To: Andy Wingo; +Cc: 19581
Hello,
Andy Wingo <wingo@pobox.com> skribis:
> On Tue 13 Jan 2015 13:58, ludo@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.
Sounds like a plan. There could be programs that will break if ‘sleep’
gives them an inexact instead of an integer. Maybe we can assume this
is an unlikely situation, though.
Thoughts?
Ludo’.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-06-23 13:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-13 12:58 bug#19581: 'sleep' return value is incorrectly rounded Ludovic Courtès
2016-06-23 9:02 ` Andy Wingo
2016-06-23 13:09 ` Ludovic Courtès
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).