This is the mail archive of the
java-prs@sourceware.cygnus.com
mailing list for the Java project.
java.lang/76: wait(timeout) always throws exception
- To: java-gnats at sourceware dot cygnus dot com
- Subject: java.lang/76: wait(timeout) always throws exception
- From: mike at pillim dot demon dot co dot uk
- Date: 24 Oct 1999 10:04:58 -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: 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: