Details
-
Bug
-
Status: Closed
-
Major - P3
-
Resolution: Fixed
-
None
-
None
-
Fully Compatible
-
ALL
-
Repl 2017-10-23
-
0
Description
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 |
|
242
|
TEST_F(ThreadPoolTest, ThreadPoolRunsOnCreateThreadFunctionBeforeConsumingTasks) {
|
243
|
bool onCreateThreadCalled = false; |
244
|
std::string taskThreadName;
|
245
|
ThreadPool::Options options;
|
246
|
options.threadNamePrefix = "mythread"; |
247
|
options.maxThreads = 1U;
|
248
|
options.onCreateThread = [&onCreateThreadCalled,
|
249
|
&taskThreadName](const std::string& threadName) { |
250
|
onCreateThreadCalled = true; |
251
|
taskThreadName = threadName;
|
252
|
};
|
253
|
|
254
|
auto& pool = makePool(options);
|
255
|
pool.startup();
|
256
|
unittest::Barrier barrier(2U);
|
257
|
ASSERT_OK(pool.schedule([&barrier] { barrier.countDownAndWait(); }));
|
258
|
barrier.countDownAndWait();
|
259
|
|
260
|
ASSERT_TRUE(onCreateThreadCalled);
|
261
|
ASSERT_EQUALS(options.threadNamePrefix + "0", taskThreadName); |
262
|
}
|