diff options
author | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2018-09-22 15:46:43 -0400 |
---|---|---|
committer | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2018-09-22 15:46:43 -0400 |
commit | 4fb0584284b2c04b67de206ad84f8b46421ed0ea (patch) | |
tree | c50c5a208e5d50460842d4780786f00440441c50 | |
parent | 9520e48a00ca6243d33310222df7787047f1b94f (diff) | |
download | mongo-4fb0584284b2c04b67de206ad84f8b46421ed0ea.tar.gz |
SERVER-37156 Wait for worker threads to exit in benchRun().
(cherry picked from commit 12dba1e5b8c5ec7532da1bfa2e05c56f021d7f06)
-rw-r--r-- | src/mongo/shell/bench.cpp | 14 | ||||
-rw-r--r-- | src/mongo/shell/bench.h | 3 |
2 files changed, 15 insertions, 2 deletions
diff --git a/src/mongo/shell/bench.cpp b/src/mongo/shell/bench.cpp index 4a56968f15f..34fb3fa4bf6 100644 --- a/src/mongo/shell/bench.cpp +++ b/src/mongo/shell/bench.cpp @@ -744,10 +744,20 @@ BenchRunWorker::BenchRunWorker(size_t id, int64_t randomSeed) : _id(id), _config(config), _brState(brState), _randomSeed(randomSeed) {} -BenchRunWorker::~BenchRunWorker() = default; +BenchRunWorker::~BenchRunWorker() { + try { + // We explicitly call join() on the started thread to ensure that any thread-local variables + // (e.g. 'currentClient' when running through mongoebench) have been destructed before + // returning from BenchRunWorker's destructor. + _thread.join(); + } catch (...) { + severe() << "caught exception in destructor: " << exceptionToStatus(); + std::terminate(); + } +} void BenchRunWorker::start() { - stdx::thread([this] { run(); }).detach(); + _thread = stdx::thread([this] { run(); }); } bool BenchRunWorker::shouldStop() const { diff --git a/src/mongo/shell/bench.h b/src/mongo/shell/bench.h index fb4618d4160..1f61b2e96f5 100644 --- a/src/mongo/shell/bench.h +++ b/src/mongo/shell/bench.h @@ -38,6 +38,7 @@ #include "mongo/platform/atomic_word.h" #include "mongo/stdx/condition_variable.h" #include "mongo/stdx/mutex.h" +#include "mongo/stdx/thread.h" #include "mongo/util/timer.h" namespace pcrecpp { @@ -477,6 +478,8 @@ private: /// Predicate, used to decide whether or not it's time to collect statistics bool shouldCollectStats() const; + stdx::thread _thread; + const size_t _id; const BenchRunConfig* _config; |