From 8a504d36f9b740c6d4c5bba6855148c5be40556e Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sat, 13 Feb 2010 12:02:34 +0100 Subject: [PATCH] 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 --- src/search.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/search.cpp b/src/search.cpp index fbae76d7..22bc0156 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -2793,9 +2793,12 @@ namespace { #else WaitForSingleObject(SitIdleEvent[threadID], INFINITE); #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 (Threads[threadID].workIsWaiting) { @@ -3051,6 +3054,8 @@ namespace { { for (int i = 1; i < ActiveThreads; i++) { + assert(Threads[i].sleeping == true); + Threads[i].idle = true; Threads[i].workIsWaiting = false; } @@ -3063,6 +3068,10 @@ namespace { for (int i = 1; i < THREAD_MAX; i++) SetEvent(SitIdleEvent[i]); #endif + + // Wait for the threads to be all woken up + for (int i = 1; i < ActiveThreads; i++) + while (Threads[i].sleeping); } } -- 2.39.2