From 65b25846c781f89097b96f2c8a261ece8ef4f831 Mon Sep 17 00:00:00 2001 From: Wesley Shillingford Date: Thu, 31 Jan 2019 21:54:09 +0000 Subject: [PATCH] Fix scope issue with mutex when setting thread names in the signature checker (#1674) --- nano/node/node.cpp | 11 +++++------ nano/node/node.hpp | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 07a69270..8e4f2c17 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -1374,7 +1374,7 @@ void nano::signature_checker::verify (nano::signature_check_set & check_a) { { // Don't process anything else if we have stopped - std::lock_guard guard (stopped_mutex); + std::lock_guard guard (mutex); if (stopped) { return; @@ -1426,7 +1426,7 @@ void nano::signature_checker::verify (nano::signature_check_set & check_a) void nano::signature_checker::stop () { - std::lock_guard guard (stopped_mutex); + std::lock_guard guard (mutex); if (!stopped) { stopped = true; @@ -1436,7 +1436,7 @@ void nano::signature_checker::stop () void nano::signature_checker::flush () { - std::lock_guard guard (stopped_mutex); + std::lock_guard guard (mutex); while (!stopped && tasks_remaining != 0) ; } @@ -1482,7 +1482,6 @@ void nano::signature_checker::set_thread_names (unsigned num_threads) auto ready = false; auto pending = num_threads; std::condition_variable cv; - std::mutex mutex_l; std::vector> promises (num_threads); std::vector> futures; futures.reserve (num_threads); @@ -1493,8 +1492,8 @@ void nano::signature_checker::set_thread_names (unsigned num_threads) for (auto i = 0u; i < num_threads; ++i) { // clang-format off - boost::asio::post (thread_pool, [&cv, &ready, &pending, &mutex_l, &promise = promises[i]]() { - std::unique_lock lk (mutex_l); + boost::asio::post (thread_pool, [&cv, &ready, &pending, &mutex = mutex, &promise = promises[i]]() { + std::unique_lock lk (mutex); nano::thread_role::set (nano::thread_role::name::signature_checking); if (--pending == 0) { diff --git a/nano/node/node.hpp b/nano/node/node.hpp index e39b467f..69c71183 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -464,7 +464,7 @@ private: static constexpr size_t batch_size = 256; const bool single_threaded; unsigned num_threads; - std::mutex stopped_mutex; + std::mutex mutex; bool stopped{ false }; };