mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 09:32:01 +00:00
Destroy resurces captured by lambda after ThreadFromGlobalPool::join().
This commit is contained in:
parent
a2c70c4611
commit
727289cb09
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user