Index: runtime/vm/thread_pool_test.cc |
diff --git a/runtime/vm/thread_pool_test.cc b/runtime/vm/thread_pool_test.cc |
index 48d2125b332d83a7e02ebddf7765a2f57fd76fdf..a555503eae905c57ef2514497de7cd3e7c01bcae 100644 |
--- a/runtime/vm/thread_pool_test.cc |
+++ b/runtime/vm/thread_pool_test.cc |
@@ -23,7 +23,17 @@ class TestTask : public ThreadPool::Task { |
: sync_(sync), done_(done) { |
} |
+ // Before running the task, *done_ should be true. This lets the caller |
+ // ASSERT things knowing that the thread is still around. To unblock the |
+ // thread, the caller should take the lock, set *done_ to false, and Notify() |
+ // the monitor. |
virtual void Run() { |
+ { |
+ MonitorLocker ml(sync_); |
+ while (*done_) { |
+ ml.Wait(); |
+ } |
+ } |
MonitorLocker ml(sync_); |
*done_ = true; |
ml.Notify(); |
@@ -38,10 +48,12 @@ class TestTask : public ThreadPool::Task { |
UNIT_TEST_CASE(ThreadPool_RunOne) { |
ThreadPool thread_pool; |
Monitor sync; |
- bool done = false; |
+ bool done = true; |
thread_pool.Run(new TestTask(&sync, &done)); |
{ |
MonitorLocker ml(&sync); |
+ done = false; |
+ ml.Notify(); |
while (!done) { |
ml.Wait(); |
} |
@@ -61,11 +73,13 @@ UNIT_TEST_CASE(ThreadPool_RunMany) { |
bool done[kTaskCount]; |
for (int i = 0; i < kTaskCount; i++) { |
- done[i] = false; |
+ done[i] = true; |
thread_pool.Run(new TestTask(&sync[i], &done[i])); |
} |
for (int i = 0; i < kTaskCount; i++) { |
MonitorLocker ml(&sync[i]); |
+ done[i] = false; |
+ ml.Notify(); |
while (!done[i]) { |
ml.Wait(); |
} |
@@ -157,12 +171,14 @@ UNIT_TEST_CASE(ThreadPool_WorkerTimeout) { |
// Run a worker. |
Monitor sync; |
- bool done = false; |
+ bool done = true; |
thread_pool.Run(new TestTask(&sync, &done)); |
EXPECT_EQ(1U, thread_pool.workers_started()); |
EXPECT_EQ(0U, thread_pool.workers_stopped()); |
{ |
MonitorLocker ml(&sync); |
+ done = false; |
+ ml.Notify(); |
while (!done) { |
ml.Wait(); |
} |