Skip to content

Commit

Permalink
seems to work
Browse files Browse the repository at this point in the history
  • Loading branch information
filimonov committed Feb 6, 2024
1 parent 0275ba1 commit ed73cee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/Common/ThreadPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,15 @@ void ThreadPoolImpl<Thread>::startThreads(bool async, std::unique_lock<std::mute
std::promise<typename std::list<Thread>::iterator> promise_thread_it;
std::future<typename std::list<Thread>::iterator> future_thread_id = promise_thread_it.get_future();

lock.unlock()
lock.unlock();

Stopwatch watch;
auto thread = Thread(&ThreadPoolImpl<Thread>::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<Thread, std::thread> ? ProfileEvents::GlobalThreadPoolThreadCreationMicroseconds : ProfileEvents::LocalThreadPoolThreadCreationMicroseconds,
Expand All @@ -355,7 +360,7 @@ void ThreadPoolImpl<Thread>::startThreads(bool async, std::unique_lock<std::mute
// return;
// }
threads.push_front(std::move(thread));
future_thread_id.set_value( threads.begin() );
promise_thread_it.set_value( threads.begin() );
}
catch (const std::exception & e)
{
Expand Down Expand Up @@ -608,9 +613,8 @@ bool ThreadPoolImpl<Thread>::finished() const
}

template <typename Thread>
void ThreadPoolImpl<Thread>::worker(std::future<typename std::list<Thread>::iterator> promise_thread_it)
void ThreadPoolImpl<Thread>::worker(typename std::list<Thread>::iterator thread_it)
{
auto thread_it = promise_thread_it.get();
DENY_ALLOCATIONS_IN_SCOPE;
CurrentMetrics::Increment metric_pool_threads(metric_threads);

Expand Down
3 changes: 2 additions & 1 deletion src/Common/ThreadPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ class ThreadPoolImpl

void calculateDesiredThreadPoolSizeNoLock();

void worker(std::future<typename std::list<Thread>::iterator> promise_thread_it);
void worker(typename std::list<Thread>::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
Expand Down

0 comments on commit ed73cee

Please sign in to comment.