[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#19581: 'sleep' return value is incorrectly rounded

From: Ludovic Courtès
Subject: bug#19581: 'sleep' return value is incorrectly rounded
Date: Tue, 13 Jan 2015 13:58:04 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]