[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.
This commit is contained in:
Evgenii Stepanov 2020-05-28 14:30:19 -07:00
parent 6eb5679402
commit 519959ad82
1 changed files with 4 additions and 1 deletions

View File

@ -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,6 +400,7 @@ TEST(ScudoWrappersCTest, DisableForkEnable) {
// Wait for the thread to be warmed up.
pthread_mutex_lock(&Mutex);
while (!Ready)
pthread_cond_wait(&Conditional, &Mutex);
pthread_mutex_unlock(&Mutex);