From 5a27030ff8494c5552a7a23884d96a7628941d60 Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Sun, 21 Jun 2020 22:51:32 -0300 Subject: [PATCH] Replace thread "pool" with a single thread When you have a comment just before your thread pool initialization that reads: // we only need 1 that is a pretty good indicator that you don't need a thread *pool* for the thing you are doing. Replace it with a single std::thread. --- src/cryptonote_core/blockchain.cpp | 5 ++--- src/cryptonote_core/blockchain.h | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index f0cf6d550..53a884eee 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -508,8 +508,7 @@ bool Blockchain::init(BlockchainDB* db, sqlite3 *lns_db, const network_type nett // create general purpose async service queue m_async_work_idle = std::unique_ptr < boost::asio::io_service::work > (new boost::asio::io_service::work(m_async_service)); - // we only need 1 - m_async_pool.create_thread([this] { m_async_service.run(); }); + m_async_thread = std::thread{[this] { m_async_service.run(); }}; #if defined(PER_BLOCK_CHECKPOINT) if (m_nettype != FAKECHAIN) @@ -647,7 +646,7 @@ bool Blockchain::deinit() // stop async service m_async_work_idle.reset(); - m_async_pool.join_all(); + m_async_thread.join(); m_async_service.stop(); // as this should be called if handling a SIGSEGV, need to check diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h index 50d914ece..06d07ee20 100644 --- a/src/cryptonote_core/blockchain.h +++ b/src/cryptonote_core/blockchain.h @@ -37,7 +37,6 @@ #include #include #include -#include #include #include #include @@ -1118,7 +1117,7 @@ namespace cryptonote difficulty_type m_difficulty_for_next_block; boost::asio::io_service m_async_service; - boost::thread_group m_async_pool; + std::thread m_async_thread; std::unique_ptr m_async_work_idle; // some invalid blocks