Fix conditional variables usage on broadcast by using a shared mutex

This commit is contained in:
Wojtek Figat
2022-01-12 17:36:06 +01:00
parent 6d676fd578
commit dfa5e91322
3 changed files with 16 additions and 16 deletions

View File

@@ -24,6 +24,7 @@ namespace ThreadPoolImpl
Array<Thread*> Threads;
ConcurrentTaskQueue<ThreadPoolTask> Jobs; // Hello Steve!
ConditionVariable JobsSignal;
CriticalSection JobsMutex;
}
void ThreadPoolTask::Enqueue()
@@ -104,7 +105,6 @@ int32 ThreadPool::ThreadProc()
ThreadPoolTask* task;
// Work until end
CriticalSection mutex;
while (Platform::AtomicRead(&ThreadPoolImpl::ExitFlag) == 0)
{
// Try to get a job
@@ -114,9 +114,9 @@ int32 ThreadPool::ThreadProc()
}
else
{
mutex.Lock();
ThreadPoolImpl::JobsSignal.Wait(mutex);
mutex.Unlock();
ThreadPoolImpl::JobsMutex.Lock();
ThreadPoolImpl::JobsSignal.Wait(ThreadPoolImpl::JobsMutex);
ThreadPoolImpl::JobsMutex.Unlock();
}
}