# HG changeset patch # User igerasim # Date 1541809288 28800 # Node ID 8a88bbeb1d1c77d7d0cd493e40ce233f8e9f35ea # Parent fad3614d1f0fd520014eef7c8c473e14a68b5ef5 8213383: Wrap up pthread_cond_wait into a loop to workaround potential spurious wakeups Reviewed-by: dlong, sspitsyn, dholmes, rriggs diff -r fad3614d1f0f -r 8a88bbeb1d1c 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); } } }