libgcj/1418: wait(timeout) wrongly throws IllegalMonitorState exception

joep@fangorn.demon.nl joep@fangorn.demon.nl
Wed Dec 20 12:26:00 GMT 2000


>Number:         1418
>Category:       libgcj
>Synopsis:       wait(timeout) wrongly throws IllegalMonitorState exception
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    tromey
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Dec 20 12:19:41 PST 2000
>Closed-Date:    Fri Nov 12 16:27:58 PST 1999
>Last-Modified:  Fri Nov 12 16:30:01 PST 1999
>Originator:     Joep Jansen
>Release:        CVS snapshot aug 7 1999
>Organization:
>Environment:
Redhat Linux 5.2, 
gcc version gcc-2.96 19990627 (experimental)
>Description:
The java::lang::Object::wait() function (natObject.cc) throws
an IllegalMonitorException when _Jv_CondWait return a non-zero
value.
However, this happens normally when the specified timeout expires,
this should not be an exception.
>How-To-Repeat:

>Fix:
_Jv_Condwait (posix-threads.cc) returns the result of either
pthread_cond_wait or pthread_cond_timedwait.
My workaround is to ignore the return value and always return zero
from _Jv_Condwait. A proper fix should check if calling thread is 
the owner of the objects monitor, and throw an IllegalMonitorStateException 
if it does not. The same is true for _Jv_CondNotify and _Jv_CondNotifyAll
>Release-Note:

>Audit-Trail:

Formerly PR libgcj/40

State-Changed-From-To: open->feedback
State-Changed-By: tromey
State-Changed-When: Sat Aug 21 19:44:26 1999
State-Changed-Why:
    I've checked in a fix for this.  I changed _Jv_CondWait
    to check for errno==ETIME; in this case it now returns 0.
    If you are running the cvs libgcj, can you check this
    and get back to me?
    If not, tell me and I will close the PR.

From: Tom Tromey <tromey@cygnus.com>
To: Joep Jansen <joep@fangorn.demon.nl>
Cc: tromey@cygnus.com, java-gnats@sourceware.cygnus.com
Subject: Re: libgcj/40
Date: Mon, 23 Aug 1999 21:14:44 -0700

 >>>>> "Joep" == Joep Jansen <joep@fangorn.demon.nl> writes:
 
 Please don't send HTML.  It is a pain to read and reply to.
 
 Joep> I checked out your patch. Unfortunately, it does not work.
 Joep> pthread_cond_timedwait returns ETIMEDOUT i.s.o. ETIMED. (see man
 Joep> page).
 
 Thanks.  I made this change.  I misread the man page on Solaris.
 
 Joep> If you change your fix to check for ETIMEDOUT, you won't get the
 Joep> IllegalMonitorStateException However, another problem still
 Joep> remains: an IllegalMonitorStateException is NOT thrown when it
 Joep> should be.
 
 It is for me, on Debian 2.0.
 Could this be a bug in RH 5.2's C library?
 
 I note that the man page doesn't mention this behavior.
 
 Tom

From: Tom Tromey <tromey@cygnus.com>
To: Joep Jansen <joep@fangorn.demon.nl>
Cc: java-gnats@sourceware.cygnus.com
Subject: Re: libgcj/40
Date: Tue, 24 Aug 1999 12:48:22 -0700

 Joep> I don't know. I am using libpthread-0.7.so.0.
 
 Me too.
 
 I don't understand why it works for me.  My simple pthread test
 program does *not* work in this situation.
 
 I'll send a simple patch under separate cover.  Can you try it and see
 if it works?
 
 Tom

From: Tom Tromey <tromey@cygnus.com>
To: joep jansen <joep@fangorn.demon.nl>
Cc: Java Gnats Server <java-gnats@sourceware.cygnus.com>
Subject: Re: libgcj/40
Date: 24 Aug 1999 13:51:17 -0600

 Could you try this patch?
 
 Tom
 
 Index: posix-threads.cc
 ===================================================================
 RCS file: /cvs/java/libgcj/libjava/posix-threads.cc,v
 retrieving revision 1.4
 diff -u -r1.4 posix-threads.cc
 --- posix-threads.cc	1999/08/24 04:01:06	1.4
 +++ posix-threads.cc	1999/08/24 19:48:02
 @@ -81,6 +81,11 @@
  #else
    pmu = &mu->mutex2;
  #endif
 +
 +  /* See if the mutex is locked by this thread.  */
 +  if (pthread_mutex_trylock (pmu))
 +    return 1;
 +
    if (millis == 0 && nanos == 0)
      r = pthread_cond_wait (cv, pmu);
    else
 @@ -95,6 +100,10 @@
        if (r && errno == ETIMEDOUT)
  	r = 0;
      }
 +
 +  /* Release the lock we acquired above.  */
 +  pthread_mutex_unlock (pmu);
 +
    return r;
  }
  
State-Changed-From-To: feedback->closed
State-Changed-By: tromey
State-Changed-When: Fri Nov 12 16:27:58 1999
State-Changed-Why:
    This has been in feedback for months.
    I assume it is fixed.

From: tromey@cygnus.com
To: java-gnats@sourceware.cygnus.com, joep@fangorn.demon.nl, tromey@cygnus.com
Cc:  
Subject: Re: libgcj/40
Date: 13 Nov 1999 00:27:58 -0000

 Synopsis: wait(timeout) wrongly throws IllegalMonitorState exception
 
 State-Changed-From-To: feedback->closed
 State-Changed-By: tromey
 State-Changed-When: Fri Nov 12 16:27:58 1999
 State-Changed-Why:
     This has been in feedback for months.
     I assume it is fixed.
 
 http://sourceware.cygnus.com/cgi-bin/gnatsweb.pl?cmd=view&database=java&pr=40
>Unformatted:




More information about the Gcc-prs mailing list