This is the mail archive of the
java-prs@sourceware.cygnus.com
mailing list for the Java project.
java.lang/77: sleep(0) sleeps forever
- To: java-gnats at sourceware dot cygnus dot com
- Subject: java.lang/77: sleep(0) sleeps forever
- From: mike at pillim dot demon dot co dot uk
- Date: 24 Oct 1999 10:05:15 -0000
- Reply-To: mike at pillim dot demon dot co dot uk
- Resent-Cc: java-prs at sourceware dot cygnus dot com, green at cygnus dot com
- Resent-Reply-To: java-gnats@sourceware.cygnus.com, mike@pillim.demon.co.uk
- Resent-To: tromey at cygnus dot com
>Number: 77
>Category: java.lang
>Synopsis: sleep(0) sleeps forever
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: tromey
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Oct 24 03:16:00 PDT 1999
>Closed-Date:
>Last-Modified:
>Originator: Mike Moreton
>Release: libgcj-2.95.1
>Organization:
>Environment:
Linux, posix threads
>Description:
If you run the progam attached in the "How-to-repeat"
section, the behavious is different under the Sun JDK and
libgcj.
Under Sun JDK 1.2.1, it's clear that sleep(0) means "sleep
for a very short time", while with libgcj the thread sleeps
until interrupted.
>How-To-Repeat:
public class TestSleep{
public static void main(String[] args) {
(new Doit()).start();
}
}
class Doit extends Thread{
public synchronized void run() {
for (int i = 0; i < 10; i++) {
System.out.println("i is now "+i);
try {
if (i==5) {
sleep(0);
} else {
sleep(1000);
}
} catch (InterruptedException e) {}
}
}
}
>Fix:
In natThread.cc, in method java::lang::Thread::sleep (jlong millis, jint nanos)
add at the start of the method the following code
if ((millis == 0) && (nanos == 0)) {
return;
}
>Release-Note:
>Audit-Trail:
>Unformatted: