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.
This commit is contained in:
Jason Rhinelander 2020-06-21 22:51:32 -03:00
parent 29b18f6cc3
commit 5a27030ff8
2 changed files with 3 additions and 5 deletions

View file

@ -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

View file

@ -37,7 +37,6 @@
#include <boost/multi_index/global_fun.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/thread/thread.hpp>
#include <atomic>
#include <functional>
#include <unordered_map>
@ -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<boost::asio::io_service::work> m_async_work_idle;
// some invalid blocks