Attempt to fix abort from parallel parsing (#42496)

This commit is contained in:
Nikita Mikhaylov 2022-10-20 17:13:18 +02:00 committed by GitHub
parent 905a4ded42
commit 4d703b792c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -178,7 +178,11 @@ public:
func = std::forward<Function>(func),
args = std::make_tuple(std::forward<Args>(args)...)]() mutable /// mutable is needed to destroy capture
{
SCOPE_EXIT(state->event.set());
SCOPE_EXIT(
{
state->finished = true;
state->event.set();
});
state->thread_id = std::this_thread::get_id();
@ -213,6 +217,17 @@ public:
~ThreadFromGlobalPoolImpl()
{
/// The problem is that the our ThreadFromGlobalPool can be actually finished
/// before we try to join the thread or check whether it is joinable or not.
/// In some places we have code like:
/// if (thread->joinable())
/// thread->join();
/// Where join() won't be executed in case when we call it
/// from the same std::thread and it will end to std::abort().
/// So we just do nothing in this case
if (state->finished)
return;
if (initialized())
abort();
}
@ -252,6 +267,9 @@ protected:
/// The state used in this object and inside the thread job.
Poco::Event event;
/// To allow joining to the same std::thread after finishing
std::atomic<bool> finished{false};
};
std::shared_ptr<State> state;