This is the mail archive of the java-prs@sourceware.cygnus.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

java.lang/76: wait(timeout) always throws exception



>Number:         76
>Category:       java.lang
>Synopsis:       wait(timeout) always throws exception
>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 call wait with a timeout, and the timeout expires,
then you get an IllegalMonitorStateException.  This is 
because java::lang::Object::wait interprets the ETIMEDOUT
response as an error.

The code attached works fine under Sun JDK 1.2.1, and causes
the exception with libgcj
>How-To-Repeat:
public class TestWait{
        public static void main(String[] args) {
                (new Doit()).doit();
        }

}

class Doit {
        public synchronized void doit() {
                for (int i = 0; i < 10; i++) {
                        System.out.println("i is now "+i);
                        try {wait(100);
                        } catch (InterruptedException e) {}
                }
        }

}
>Fix:
In posix-threads.cc
method _Jv_CondWait (_Jv_ConditionVariable_t *cv, _Jv_Mutex_t *mu,
              jlong millis, jint nanos)
after the "r = pthread_cond_timedwait (cv, pmu, &ts);" line
add the following:-

      /*
       * Timeouts shouldn't be reported as an error.
       */
      if (r == ETIMEDOUT) {
        r = 0;
      }
>Release-Note:
>Audit-Trail:
>Unformatted:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]