summaryrefslogtreecommitdiff
path: root/src/mongo/util/concurrency
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2017-10-10 13:16:26 -0400
committerBenety Goh <benety@mongodb.com>2017-10-13 10:16:35 -0400
commit24e23ac82f32e24fb9ea2235ec9093c6688552b1 (patch)
tree6ae7add71f2f50cf6a8f6c6f75685aea11ba6474 /src/mongo/util/concurrency
parentba0ee77c61c39b077d0975b7487099c5985c7b18 (diff)
downloadmongo-24e23ac82f32e24fb9ea2235ec9093c6688552b1.tar.gz
SERVER-31491 fix race in ThreadPoolTest::ThreadPoolRunsOnCreateThreadFunctionBeforeConsumingTasks
This patch fixes the relative scopes of the Barrier and ThreadPool instances in the test function. Since the thread function provided to the ThreadPool refer to the Barrier, the Barrier must outlive the ThreadPool.
Diffstat (limited to 'src/mongo/util/concurrency')
-rw-r--r--src/mongo/util/concurrency/thread_pool_test.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/mongo/util/concurrency/thread_pool_test.cpp b/src/mongo/util/concurrency/thread_pool_test.cpp
index e0f548a5b91..9234aeeb4ab 100644
--- a/src/mongo/util/concurrency/thread_pool_test.cpp
+++ b/src/mongo/util/concurrency/thread_pool_test.cpp
@@ -240,6 +240,8 @@ DEATH_TEST(ThreadPoolTest,
}
TEST_F(ThreadPoolTest, ThreadPoolRunsOnCreateThreadFunctionBeforeConsumingTasks) {
+ unittest::Barrier barrier(2U);
+
bool onCreateThreadCalled = false;
std::string taskThreadName;
ThreadPool::Options options;
@@ -251,9 +253,9 @@ TEST_F(ThreadPoolTest, ThreadPoolRunsOnCreateThreadFunctionBeforeConsumingTasks)
taskThreadName = threadName;
};
- auto& pool = makePool(options);
+ ThreadPool pool(options);
pool.startup();
- unittest::Barrier barrier(2U);
+
ASSERT_OK(pool.schedule([&barrier] { barrier.countDownAndWait(); }));
barrier.countDownAndWait();