Core/TaskScheduler: Fix WaitForTasks returning before all tasks are executed
This could happen because a worker only counts as active when starting a job, but after acquiring one. So one possibility was that : 1. All workers except W1 and W2 are idle 2. W1 is about to notify as idle, as W2 got a task (but did not notify as active yet) 3. W1 notifies as idle, idle count == worker count -> wake main thread 4. W2 didn't run its task yet
This commit is contained in:
parent
653e56f8ce
commit
8b9b47ba59
|
|
@ -130,7 +130,6 @@ namespace Nz
|
|||
std::shuffle(randomWorkerIndices.begin(), randomWorkerIndices.end(), gen);
|
||||
}
|
||||
|
||||
bool idle = false;
|
||||
do
|
||||
{
|
||||
// Get a task
|
||||
|
|
@ -152,12 +151,6 @@ namespace Nz
|
|||
|
||||
if (task)
|
||||
{
|
||||
if (idle)
|
||||
{
|
||||
m_owner.NotifyWorkerActive();
|
||||
idle = false;
|
||||
}
|
||||
|
||||
#ifdef NAZARA_WITH_TSAN
|
||||
// Workaround for TSan false-positive
|
||||
__tsan_acquire(task);
|
||||
|
|
@ -173,14 +166,12 @@ namespace Nz
|
|||
else
|
||||
{
|
||||
// Wait for tasks if we don't have any right now
|
||||
if (!idle)
|
||||
{
|
||||
m_owner.NotifyWorkerIdle();
|
||||
idle = true;
|
||||
}
|
||||
m_owner.NotifyWorkerIdle();
|
||||
|
||||
m_notifier.wait(false);
|
||||
m_notifier.clear();
|
||||
|
||||
m_owner.NotifyWorkerActive();
|
||||
}
|
||||
}
|
||||
while (m_running.load(std::memory_order_relaxed));
|
||||
|
|
|
|||
Loading…
Reference in New Issue