From 727289cb09b4e0e57008b7a8accf57cd7f8ca397 Mon Sep 17 00:00:00 2001 From: Nikolai Kochetov Date: Tue, 29 Sep 2020 23:43:02 +0300 Subject: [PATCH] Destroy resurces captured by lambda after ThreadFromGlobalPool::join(). --- src/Common/ThreadPool.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Common/ThreadPool.h b/src/Common/ThreadPool.h index 4f08427b4b9..77e0876d1cf 100644 --- a/src/Common/ThreadPool.h +++ b/src/Common/ThreadPool.h @@ -11,6 +11,7 @@ #include #include +#include /** Very simple thread pool similar to boost::threadpool. @@ -161,21 +162,21 @@ public: GlobalThreadPool::instance().scheduleOrThrow([ state = state, func = std::forward(func), - args = std::make_tuple(std::forward(args)...)] + args = std::make_tuple(std::forward(args)...)]() mutable { SCOPE_EXIT({ - /// Destroy function before exit. + /// Destroy function before exit. /// It will guarantee that after ThreadFromGlobalPool::join all captured params are destroyed. - func = {}; state->set(); }); + auto function = std::move(func); auto arguments = std::move(args); /// Thread status holds raw pointer on query context, thus it always must be destroyed /// before sending signal that permits to join this thread. DB::ThreadStatus thread_status; - std::apply(func, arguments); + std::apply(function, arguments); }); }