GNU bug report logs - #19581
'sleep' return value is incorrectly rounded

Previous Next

Package: guile;

Reported by: ludo <at> gnu.org (Ludovic Courtès)

Date: Tue, 13 Jan 2015 12:59:02 UTC

Severity: normal

Full log


View this message in rfc822 format

From: ludo <at> gnu.org (Ludovic Courtès)
To: Andy Wingo <wingo <at> pobox.com>
Cc: 19581 <at> debbugs.gnu.org
Subject: bug#19581: 'sleep' return value is incorrectly rounded
Date: Thu, 23 Jun 2016 15:09:22 +0200
Hello,

Andy Wingo <wingo <at> pobox.com> skribis:

> 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.

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’.




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.