mirror of
https://github.com/yse/easy_profiler.git
synced 2024-12-27 08:41:02 +08:00
#0 [Gui] Thread pool fix: there was a possibility that not all tasks would be executed
This commit is contained in:
parent
b6b988e274
commit
b07de42a48
@ -115,15 +115,23 @@ void ThreadPool::work()
|
|||||||
if (m_interrupt.load(std::memory_order_acquire))
|
if (m_interrupt.load(std::memory_order_acquire))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (m_tasks.empty())
|
while (true) // execute all available tasks
|
||||||
continue;
|
{
|
||||||
|
if (m_tasks.empty())
|
||||||
|
break; // the lock will be released on the outer loop new iteration
|
||||||
|
|
||||||
auto& task = m_tasks.front().get();
|
auto& task = m_tasks.front().get();
|
||||||
task.setStatus(TaskStatus::Processing);
|
task.setStatus(TaskStatus::Processing);
|
||||||
m_tasks.pop_front();
|
m_tasks.pop_front();
|
||||||
|
|
||||||
lock.unlock();
|
// unlock to permit tasks execution for other worker threads
|
||||||
|
lock.unlock();
|
||||||
|
|
||||||
task.execute();
|
// execute task
|
||||||
|
task.execute();
|
||||||
|
|
||||||
|
// lock again to check if there are new tasks in the queue
|
||||||
|
lock.lock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user