libgcj/1457: sleep(0) sleeps forever

mike@pillim.demon.co.uk mike@pillim.demon.co.uk
Wed Dec 20 12:28:00 GMT 2000


>Number:         1457
>Category:       libgcj
>Synopsis:       sleep(0) sleeps forever
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    tromey
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Dec 20 12:20:09 PST 2000
>Closed-Date:    Mon Oct 25 16:49:32 PDT 1999
>Last-Modified:  Mon Oct 25 16:50:00 PDT 1999
>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:

Formerly PR java.lang/77

State-Changed-From-To: open->closed
State-Changed-By: bryce
State-Changed-When: Mon Oct 25 16:49:32 1999
State-Changed-Why:
    Known bug in libgcj 2.95.x, already fixed in cvs and snapshot releases.

From: bryce@albatross.co.nz
To: java-gnats@sourceware.cygnus.com, mike@pillim.demon.co.uk,
  tromey@cygnus.com
Cc:  
Subject: Re: java.lang/77
Date: 25 Oct 1999 23:49:32 -0000

 Synopsis: sleep(0) sleeps forever
 
 State-Changed-From-To: open->closed
 State-Changed-By: bryce
 State-Changed-When: Mon Oct 25 16:49:32 1999
 State-Changed-Why:
     Known bug in libgcj 2.95.x, already fixed in cvs and snapshot releases.
 
 http://sourceware.cygnus.com/cgi-bin/gnatsweb.pl?cmd=view&database=java&pr=77
>Unformatted:




More information about the Gcc-prs mailing list