summaryrefslogtreecommitdiff
path: root/src/mongo/util/concurrency
diff options
context:
space:
mode:
authorAmirsaman Memaripour <amirsaman.memaripour@mongodb.com>2020-05-26 14:24:08 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-06-02 13:22:38 +0000
commit3b7bc03a8f8b964769ff708674163b67ddd1a450 (patch)
tree77248252074ae22667ad87cdd9dd6d6f15dd4a88 /src/mongo/util/concurrency
parentb348cccce22b4b3a8bc26d3d840c64fe15915a04 (diff)
downloadmongo-3b7bc03a8f8b964769ff708674163b67ddd1a450.tar.gz
SERVER-48346 Fix lifetime issues for barriers captured by reference
Extends the lifetime of barriers that are referenced by background threads and their reference could outlive the barrier's owner.
Diffstat (limited to 'src/mongo/util/concurrency')
-rw-r--r--src/mongo/util/concurrency/thread_pool_test.cpp22
1 files changed, 9 insertions, 13 deletions
diff --git a/src/mongo/util/concurrency/thread_pool_test.cpp b/src/mongo/util/concurrency/thread_pool_test.cpp
index 30e5dbd0ddc..0b456c6abc1 100644
--- a/src/mongo/util/concurrency/thread_pool_test.cpp
+++ b/src/mongo/util/concurrency/thread_pool_test.cpp
@@ -32,8 +32,10 @@
#include "mongo/platform/basic.h"
#include <boost/optional.hpp>
+#include <fmt/format.h>
#include "mongo/base/init.h"
+#include "mongo/platform/atomic_word.h"
#include "mongo/platform/mutex.h"
#include "mongo/stdx/condition_variable.h"
#include "mongo/stdx/thread.h"
@@ -48,6 +50,7 @@
namespace {
using namespace mongo;
+using namespace fmt::literals;
MONGO_INITIALIZER(ThreadPoolCommonTests)(InitializerContext*) {
addTestsForThreadPool("ThreadPoolCommon",
@@ -256,29 +259,22 @@ DEATH_TEST_REGEX(ThreadPoolTest,
TEST_F(ThreadPoolTest, ThreadPoolRunsOnCreateThreadFunctionBeforeConsumingTasks) {
unittest::Barrier barrier(2U);
-
- bool onCreateThreadCalled = false;
- std::string taskThreadName;
+ std::string journal;
ThreadPool::Options options;
options.threadNamePrefix = "mythread";
options.maxThreads = 1U;
- options.onCreateThread = [&onCreateThreadCalled,
- &taskThreadName](const std::string& threadName) {
- onCreateThreadCalled = true;
- taskThreadName = threadName;
+ options.onCreateThread = [&](const std::string& threadName) {
+ journal.append("[onCreate({})]"_format(threadName));
};
ThreadPool pool(options);
pool.startup();
-
- pool.schedule([&barrier](auto status) {
- ASSERT_OK(status);
+ pool.schedule([&](auto status) {
+ journal.append("[Call({})]"_format(status.toString()));
barrier.countDownAndWait();
});
barrier.countDownAndWait();
-
- ASSERT_TRUE(onCreateThreadCalled);
- ASSERT_EQUALS(options.threadNamePrefix + "0", taskThreadName);
+ ASSERT_EQUALS(journal, "[onCreate(mythread0)][Call(OK)]");
}
TEST(ThreadPoolTest, JoinAllRetiredThreads) {