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

This commit is contained in:
Nikolai Kochetov 2020-09-29 22:11:40 +03:00
parent a7e7fd084f
commit a2c70c4611

View File

@ -163,24 +163,19 @@ public:
func = std::forward<Function>(func),
args = std::make_tuple(std::forward<Args>(args)...)]
{
try
{
/// Move capture in order to destroy it before `state->set()`.
/// It will guarantee that after ThreadFromGlobalPool::join all resources are destroyed.
auto function = std::move(func);
auto arguments = std::move(args);
SCOPE_EXIT({
/// Destroy function before exit.
/// It will guarantee that after ThreadFromGlobalPool::join all captured params are destroyed.
func = {};
state->set();
});
/// 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(function, arguments);
}
catch (...)
{
state->set();
throw;
}
state->set();
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);
});
}