changeset 53430:8a88bbeb1d1c

8213383: Wrap up pthread_cond_wait into a loop to workaround potential spurious wakeups Reviewed-by: dlong, sspitsyn, dholmes, rriggs
author igerasim
date Fri, 09 Nov 2018 16:21:28 -0800
parents fad3614d1f0f
children 5643a5bff514
files src/java.base/unix/native/libjsig/jsig.c
diffstat 1 files changed, 6 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/unix/native/libjsig/jsig.c	Fri Nov 09 15:19:33 2018 -0500
+++ b/src/java.base/unix/native/libjsig/jsig.c	Fri Nov 09 16:21:28 2018 -0800
@@ -77,7 +77,7 @@
 /* Used to synchronize the installation of signal handlers. */
 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
 static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
-static pthread_t tid = 0;
+static pthread_t tid;
 
 typedef void (*sa_handler_t)(int);
 typedef void (*sa_sigaction_t)(int, siginfo_t *, void *);
@@ -110,8 +110,11 @@
   /* When the jvm is installing its set of signal handlers, threads
    * other than the jvm thread should wait. */
   if (jvm_signal_installing) {
-    if (tid != pthread_self()) {
-      pthread_cond_wait(&cond, &mutex);
+    /* tid is not initialized until jvm_signal_installing is set to true. */
+    if (pthread_equal(tid, pthread_self()) == 0) {
+      do {
+        pthread_cond_wait(&cond, &mutex);
+      } while (jvm_signal_installing);
     }
   }
 }