[compiler-rt] 519959a - [scudo] Fix deadlock in ScudoWrappersCTest.DisableForkEnable test.
Evgenii Stepanov via llvm-commits
llvm-commits at lists.llvm.org
Thu May 28 14:31:44 PDT 2020
Author: Evgenii Stepanov
Date: 2020-05-28T14:31:33-07:00
New Revision: 519959ad825bfad0b62a2012c064e582788d8f21
URL: https://github.com/llvm/llvm-project/commit/519959ad825bfad0b62a2012c064e582788d8f21
DIFF: https://github.com/llvm/llvm-project/commit/519959ad825bfad0b62a2012c064e582788d8f21.diff
LOG: [scudo] Fix deadlock in ScudoWrappersCTest.DisableForkEnable test.
pthread_cond_wait needs a loop around it to handle spurious wake ups,
as well as the case when signal runs before wait.
Added:
Modified:
compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp b/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
index 8b2bc6ecbd5b..b41908cf4781 100644
--- a/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
@@ -372,6 +372,7 @@ TEST(ScudoWrappersCTest, Fork) {
static pthread_mutex_t Mutex;
static pthread_cond_t Conditional = PTHREAD_COND_INITIALIZER;
+static bool Ready;
static void *enableMalloc(void *Unused) {
// Initialize the allocator for this thread.
@@ -382,6 +383,7 @@ static void *enableMalloc(void *Unused) {
// Signal the main thread we are ready.
pthread_mutex_lock(&Mutex);
+ Ready = true;
pthread_cond_signal(&Conditional);
pthread_mutex_unlock(&Mutex);
@@ -398,7 +400,8 @@ TEST(ScudoWrappersCTest, DisableForkEnable) {
// Wait for the thread to be warmed up.
pthread_mutex_lock(&Mutex);
- pthread_cond_wait(&Conditional, &Mutex);
+ while (!Ready)
+ pthread_cond_wait(&Conditional, &Mutex);
pthread_mutex_unlock(&Mutex);
// Disable the allocator and fork. fork should succeed after malloc_enable.
More information about the llvm-commits
mailing list