From ed73cee02fd4af9fa41d3caa2d0cd1b20de4d831 Mon Sep 17 00:00:00 2001 From: Mikhail Filimonov Date: Tue, 6 Feb 2024 21:12:38 +0100 Subject: [PATCH] seems to work --- src/Common/ThreadPool.cpp | 14 +++++++++----- src/Common/ThreadPool.h | 3 ++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Common/ThreadPool.cpp b/src/Common/ThreadPool.cpp index 1f4fbf6a2b67..a92b2e3a04f1 100644 --- a/src/Common/ThreadPool.cpp +++ b/src/Common/ThreadPool.cpp @@ -335,10 +335,15 @@ void ThreadPoolImpl::startThreads(bool async, std::unique_lock::iterator> promise_thread_it; std::future::iterator> future_thread_id = promise_thread_it.get_future(); - lock.unlock() + lock.unlock(); Stopwatch watch; - auto thread = Thread(&ThreadPoolImpl::worker, this, std::move(future_thread_id)); + + auto thread = Thread([this, ft = std::move(future_thread_id)] mutable + { + auto thread_it = ft.get(); + worker(thread_it); + }); ProfileEvents::increment( std::is_same_v ? ProfileEvents::GlobalThreadPoolThreadCreationMicroseconds : ProfileEvents::LocalThreadPoolThreadCreationMicroseconds, @@ -355,7 +360,7 @@ void ThreadPoolImpl::startThreads(bool async, std::unique_lock::finished() const } template -void ThreadPoolImpl::worker(std::future::iterator> promise_thread_it) +void ThreadPoolImpl::worker(typename std::list::iterator thread_it) { - auto thread_it = promise_thread_it.get(); DENY_ALLOCATIONS_IN_SCOPE; CurrentMetrics::Increment metric_pool_threads(metric_threads); diff --git a/src/Common/ThreadPool.h b/src/Common/ThreadPool.h index bdfa223dfe88..6627f08835cc 100644 --- a/src/Common/ThreadPool.h +++ b/src/Common/ThreadPool.h @@ -151,7 +151,8 @@ class ThreadPoolImpl void calculateDesiredThreadPoolSizeNoLock(); - void worker(std::future::iterator> promise_thread_it); + void worker(typename std::list::iterator future_thread_it); + /// if number of threads is less than desired, creates new threads /// for async mode it creates a task that creates new threads