Destroy resurces captured by lambda after ThreadFromGlobalPool::join().

This commit is contained in:
Nikolai Kochetov 2020-09-29 23:43:02 +03:00
parent a2c70c4611
commit 727289cb09

View File

@ -11,6 +11,7 @@
#include <Poco/Event.h>
#include <Common/ThreadStatus.h>
#include <ext/scope_guard.h>
/** Very simple thread pool similar to boost::threadpool.
@ -161,21 +162,21 @@ public:
GlobalThreadPool::instance().scheduleOrThrow([
state = state,
func = std::forward<Function>(func),
args = std::make_tuple(std::forward<Args>(args)...)]
args = std::make_tuple(std::forward<Args>(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);
});
}