This is the mail archive of the
libc-alpha@sourceware.cygnus.com
mailing list for the glibc project.
[comp.os.linux.development.system] Bug in glibc-2.1.1: sleep(0) sleeps 10ms
- To: libc-alpha at sourceware dot cygnus dot com
- Subject: [comp.os.linux.development.system] Bug in glibc-2.1.1: sleep(0) sleeps 10ms
- From: Andreas Jaeger <aj at suse dot de>
- Date: 14 Oct 1999 18:54:42 +0200
- Cc: peer at knoll-is dot de
Should we add:
if (seconds == 0)
return 0;
to sleep to optimize sleep (0) ?
AFAIK POSIX notes that "sleep may sleep for longer than the amount of
time requested". Nevertheless I'm appending the trivial patch.
Andreas
P.S. Peer, the right way to report bugs in glibc is to use the
glibcbug script.
1999-10-14 Andreas Jaeger <aj@suse.de>
* sysdeps/unix/sysv/linux/sleep.c (__sleep): Optimize for zero
seconds. Reported by Peer Griebel <peer@knoll-is.de>.
Index: sysdeps/unix/sysv/linux/sleep.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/sleep.c,v
retrieving revision 1.6
diff -u -u -r1.6 sleep.c
--- sleep.c 1998/11/17 20:39:23 1.6
+++ sleep.c 1999/10/14 16:52:54
@@ -34,6 +34,9 @@
struct sigaction oact;
unsigned int result;
+ if (seconds == 0)
+ return 0;
+
/* Linux will wake up the system call, nanosleep, when SIGCHLD
arrives even if SIGCHLD is ignored. We have to deal with it
in libc. We block SIGCHLD first. */
- Subject: Bug in glibc-2.1.1: sleep(0) sleeps 10ms
- From: peer at knoll-is dot de (Dr. Peer Griebel)
- Date: Thu, 14 Oct 1999 08:57:55 GMT
- Newsgroups: comp.os.linux.development.system
- Organization: Gigabell Newsserver @ Gigabell
- Xref: news2.suse.de comp.os.linux.development.system:2234
Hi,
I hope this is the right forum to inform about in bug in glibc-2.1.1.
Otherwise please tell me where to go. (I don't know the adress of a
glibc mailing list).
We just ported our very large ERP system to linux. All went well but
the programs were very slow.
After 3 days of bug hunting I observed that our debugging package uses
sleep(0) very often. In all OSes we already used this makes no
problem. But glibc-2.1.1 uses nanosleep() to implement sleep(). A call
of nanosleep to sleep for 0 seconds results in a sleep of at least
10ms (as also described in the manual page).
We think this is a bug. sleep() should check for a argument of 0 and
simply return in this case.
glibc-2.0.7 doesn't have this problem, because this version does not
use nanosleep() to imlement sleep().
This bug is currently no problem for us any longer. We simply check
ourselves for a 0 argument to sleep. But it might happen that other
people also run into this same problem.
Peer.
--
Andreas Jaeger aj@suse.de aj@arthur.rhein-neckar.de