8213383: Wrap up pthread_cond_wait into a loop to workaround potential spurious wakeups
authorigerasim
Fri, 09 Nov 2018 16:21:28 -0800
changeset 52482 8a88bbeb1d1c
parent 52481 fad3614d1f0f
child 52483 5643a5bff514
8213383: Wrap up pthread_cond_wait into a loop to workaround potential spurious wakeups Reviewed-by: dlong, sspitsyn, dholmes, rriggs
src/java.base/unix/native/libjsig/jsig.c
--- 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);
     }
   }
 }