Reset job on failure too in ThreadPool::worker()

job should be reseted before decrementing scheduled_jobs to
ensure that the Job destroyed before wait() returns.
This commit is contained in:
Azat Khuzhin 2020-09-22 12:14:37 +03:00
parent bd531bb045
commit 789434994a

View File

@ -234,10 +234,16 @@ void ThreadPoolImpl<Thread>::worker(typename std::list<Thread>::iterator thread_
std::is_same_v<Thread, std::thread> ? CurrentMetrics::GlobalThreadActive : CurrentMetrics::LocalThreadActive);
job();
/// job should be reseted before decrementing scheduled_jobs to
/// ensure that the Job destroyed before wait() returns.
job = {};
}
catch (...)
{
/// job should be reseted before decrementing scheduled_jobs to
/// ensure that the Job destroyed before wait() returns.
job = {};
{
std::unique_lock lock(mutex);
if (!first_exception)