public inbox for java-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Use pthread_equal to compare thread IDs
       [not found] <287047809.18185663.1363202448566.JavaMail.root@redhat.com>
@ 2013-03-13 19:24 ` Andrew Hughes
  2013-03-13 19:51   ` Andrew Haley
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Hughes @ 2013-03-13 19:24 UTC (permalink / raw)
  To: GCJ-patches

[-- Attachment #1: Type: text/plain, Size: 1630 bytes --]

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pthread_equal.patch --]
[-- Type: text/x-patch; name=pthread_equal.patch, Size: 428 bytes --]

Index: libjava/include/posix-threads.h
===================================================================
--- libjava/include/posix-threads.h	(revision 196601)
+++ libjava/include/posix-threads.h	(working copy)
@@ -79,7 +79,7 @@
 inline int
 _Jv_MutexCheckMonitor (_Jv_Mutex_t *mu)
 {
-  return (mu->owner != pthread_self());
+  return (pthread_equal(mu->owner, pthread_self()) == 0);
 }
 
 // Type identifying a POSIX thread.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Use pthread_equal to compare thread IDs
  2013-03-13 19:24 ` [PATCH] Use pthread_equal to compare thread IDs Andrew Hughes
@ 2013-03-13 19:51   ` Andrew Haley
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Haley @ 2013-03-13 19:51 UTC (permalink / raw)
  To: Andrew Hughes; +Cc: GCJ-patches

On 03/13/2013 07:24 PM, Andrew Hughes wrote:
> 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?

Yes, thanks.

Andrew.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-03-13 19:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <287047809.18185663.1363202448566.JavaMail.root@redhat.com>
2013-03-13 19:24 ` [PATCH] Use pthread_equal to compare thread IDs Andrew Hughes
2013-03-13 19:51   ` Andrew Haley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).