-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Concurrency
-
None
-
Fully Compatible
-
ALL
-
Repl 2017-10-23
-
0
In this test function, since the thread function provided to the ThreadPool relies on the Barrier, it is incorrect for the Barrier to have a shorter lifespan than the ThreadPool instance.
thread_pool_test.cpp
TEST_F(ThreadPoolTest, ThreadPoolRunsOnCreateThreadFunctionBeforeConsumingTasks) { bool onCreateThreadCalled = false; std::string taskThreadName; ThreadPool::Options options; options.threadNamePrefix = "mythread"; options.maxThreads = 1U; options.onCreateThread = [&onCreateThreadCalled, &taskThreadName](const std::string& threadName) { onCreateThreadCalled = true; taskThreadName = threadName; }; auto& pool = makePool(options); pool.startup(); unittest::Barrier barrier(2U); ASSERT_OK(pool.schedule([&barrier] { barrier.countDownAndWait(); })); barrier.countDownAndWait(); ASSERT_TRUE(onCreateThreadCalled); ASSERT_EQUALS(options.threadNamePrefix + "0", taskThreadName); }