From d7d22684f4f5b846253cfaaba90d029a4da037aa Mon Sep 17 00:00:00 2001 From: Vibhav Pant Date: Tue, 29 Aug 2023 14:02:32 +0530 Subject: [PATCH] Start the thread pool on construction. --- internal/platform/implementation/linux/thread_pool.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/platform/implementation/linux/thread_pool.cc b/internal/platform/implementation/linux/thread_pool.cc index dcbc72ef..fdcf2466 100644 --- a/internal/platform/implementation/linux/thread_pool.cc +++ b/internal/platform/implementation/linux/thread_pool.cc @@ -26,6 +26,7 @@ namespace linux { ThreadPool::ThreadPool(size_t max_pool_size) : max_pool_size_(max_pool_size), shut_down_(false) { threads_.reserve(max_pool_size); + Start(); } ThreadPool::~ThreadPool() { ShutDown(); } @@ -55,6 +56,9 @@ bool ThreadPool::Start() { } }; + NEARBY_LOGS(INFO) << __func__ << ": Starting thread pool with " + << max_pool_size_ << " threads"; + for (size_t i = 0; i < max_pool_size_; i++) { threads_.emplace_back(runner); } @@ -70,7 +74,7 @@ bool ThreadPool::Run(Runnable &&task) { absl::MutexLock l(&mutex_); if (threads_.empty()) { - NEARBY_LOGS(ERROR) << __func__ << "thread pool is not active"; + NEARBY_LOGS(ERROR) << __func__ << ": thread pool is not active"; return false; }