Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(257)

Unified Diff: runtime/vm/thread_pool_test.cc

Issue 2478243004: Fix thread pool tests (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698