aboutsummaryrefslogtreecommitdiffhomepage
path: root/iothread.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-05-29 13:44:31 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-05-29 13:44:31 -0700
commit2dfd57bb8ce6bb8f8283ccedb0c3c19422c0b297 (patch)
treefda5f5fe1f432886f6597f107ba28017ca267776 /iothread.cpp
parent20d7a142c54db5a4680c21e7d464b1a5aa8aae35 (diff)
Hopeful fix for hangs in iothread tests in travis-ci
Diffstat (limited to 'iothread.cpp')
-rw-r--r--iothread.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/iothread.cpp b/iothread.cpp
index 65bc4144..eb6b3ccd 100644
--- a/iothread.cpp
+++ b/iothread.cpp
@@ -315,7 +315,13 @@ static void iothread_service_main_thread_requests(void)
req->done = true;
}
- // Ok, we've handled everybody. Announce the good news, and allow ourselves to be unlocked
+ /* Ok, we've handled everybody. Announce the good news, and allow ourselves to be unlocked. Note we must do this while holding the lock. Otherwise we race with the waiting threads:
+ 1. waiting thread checks for done, sees false
+ 2. main thread performs request, sets done to true, posts to condition
+ 3. waiting thread unlocks lock, waits on condition (forever)
+ Because the waiting thread performs step 1 under the lock, if we take the lock, we avoid posting before the waiting thread is waiting.
+ */
+ scoped_lock broadcast_lock(s_main_thread_performer_lock);
VOMIT_ON_FAILURE(pthread_cond_broadcast(&s_main_thread_performer_condition));
}
}