public inbox for java-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew Hughes <gnu.andrew@redhat.com>
To: GCJ-patches <java-patches@gcc.gnu.org>
Subject: [PATCH] Use pthread_equal to compare thread IDs
Date: Wed, 13 Mar 2013 19:24:00 -0000	[thread overview]
Message-ID: <1186349091.18187087.1363202660791.JavaMail.root@redhat.com> (raw)
In-Reply-To: <287047809.18185663.1363202448566.JavaMail.root@redhat.com>

[-- 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.

       reply	other threads:[~2013-03-13 19:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <287047809.18185663.1363202448566.JavaMail.root@redhat.com>
2013-03-13 19:24 ` Andrew Hughes [this message]
2013-03-13 19:51   ` Andrew Haley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1186349091.18187087.1363202660791.JavaMail.root@redhat.com \
    --to=gnu.andrew@redhat.com \
    --cc=java-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).