[PATCH] Use pthread_equal to compare thread IDs

Andrew Hughes gnu.andrew@redhat.com
Wed Mar 13 19:24:00 GMT 2013


We've recently seen some sporadic IllegalMonitorStateException failures from
gcj on amd64, ppc32 & ppc64 when building IcedTea against the latest glibc.
Due to the nature of the failure, it's hard to confirm that the attached patch
will fix the issue, but it seems correct to remedy this either way.

When determining if the mutex is held by the current thread in notifyAll,
gcj's POSIX threads implementation compares the result of pthread_self
and the owner of the mutex using !=.  However, pthread_self's man page
states:

"POSIX.1 allows an implementation wide freedom in choosing the type used to represent a thread ID; for
example,  representation  using  either an arithmetic type or a structure is permitted.  Therefore, variables of
type pthread_t can't portably be compared using the C equality operator (==); use pthread_equal(3) instead.
Thread identifiers should be considered opaque: any attempt to use a thread ID other than in pthreads  calls
is nonportable and can lead to unspecified results."

While the use of !=  has worked in the past, I suspect a change in glibc
may have broken this.  Either way, it seems sensible to fix this and use
pthread_equal to compare the identifiers as in the attached patch.

ChangeLog:

2013-03-12  Andrew John Hughes  <gnu.andrew@redhat.com>

        * include/posix-threads.h:
        (_Jv_MutexCheckMonitor(_Jv_Mutex_t)): Use
        pthread_equal rather than !=.

Ok for trunk?
-- 
Andrew :)

Free Java Software Engineer
Red Hat, Inc. (http://www.redhat.com)

PGP Key: 248BDC07 (https://keys.indymedia.org/)
Fingerprint = EC5A 1F5E C0AD 1D15 8F1F  8F91 3B96 A578 248B DC07

-------------- next part --------------
A non-text attachment was scrubbed...
Name: pthread_equal.patch
Type: text/x-patch
Size: 428 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/java-patches/attachments/20130313/06f76ef3/attachment.bin>


More information about the Java-patches mailing list