mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-21 01:27:16 +08:00
Be sure threads are woken in wake_sleeping_threads()
Wait inside wake_sleeping_threads() for the threads to be effectively and reliably woken up. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
@@ -2793,9 +2793,12 @@ namespace {
|
|||||||
#else
|
#else
|
||||||
WaitForSingleObject(SitIdleEvent[threadID], INFINITE);
|
WaitForSingleObject(SitIdleEvent[threadID], INFINITE);
|
||||||
#endif
|
#endif
|
||||||
Threads[threadID].sleeping = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Out of the while loop to avoid races in case thread is woken up but
|
||||||
|
// while condition still holds true so that is put to sleep again.
|
||||||
|
Threads[threadID].sleeping = false;
|
||||||
|
|
||||||
// If this thread has been assigned work, launch a search
|
// If this thread has been assigned work, launch a search
|
||||||
if (Threads[threadID].workIsWaiting)
|
if (Threads[threadID].workIsWaiting)
|
||||||
{
|
{
|
||||||
@@ -3051,6 +3054,8 @@ namespace {
|
|||||||
{
|
{
|
||||||
for (int i = 1; i < ActiveThreads; i++)
|
for (int i = 1; i < ActiveThreads; i++)
|
||||||
{
|
{
|
||||||
|
assert(Threads[i].sleeping == true);
|
||||||
|
|
||||||
Threads[i].idle = true;
|
Threads[i].idle = true;
|
||||||
Threads[i].workIsWaiting = false;
|
Threads[i].workIsWaiting = false;
|
||||||
}
|
}
|
||||||
@@ -3063,6 +3068,10 @@ namespace {
|
|||||||
for (int i = 1; i < THREAD_MAX; i++)
|
for (int i = 1; i < THREAD_MAX; i++)
|
||||||
SetEvent(SitIdleEvent[i]);
|
SetEvent(SitIdleEvent[i]);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Wait for the threads to be all woken up
|
||||||
|
for (int i = 1; i < ActiveThreads; i++)
|
||||||
|
while (Threads[i].sleeping);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user