X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fsearch.cpp;h=ac870f5bf617aa8d75fbdede2e5e04048eaf970c;hp=9252dfa6fa1d35724f94f4c32b62f5a24b7fb7c3;hb=4ad03c9bad914b337fb6431c4bcbc1d909a1a841;hpb=dedc6d758837a9ac141832fb69c2258b4711ea56 diff --git a/src/search.cpp b/src/search.cpp index 9252dfa6..ac870f5b 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -94,8 +94,8 @@ namespace { int ActiveThreads; volatile bool AllThreadsShouldExit; Thread threads[MAX_THREADS]; - Lock MPLock, WaitLock; - WaitCondition WaitCond[MAX_THREADS]; + Lock MPLock, SleepLock[MAX_THREADS]; + WaitCondition SleepCond[MAX_THREADS]; }; @@ -2227,7 +2227,7 @@ split_point_start: // At split points actual search starts from here threads[threadID].state = THREAD_AVAILABLE; // Grab the lock to avoid races with wake_sleeping_thread() - lock_grab(&WaitLock); + lock_grab(&SleepLock[threadID]); // If we are master and all slaves have finished do not go to sleep for (i = 0; sp && i < ActiveThreads && !sp->slaves[i]; i++) {} @@ -2235,15 +2235,15 @@ split_point_start: // At split points actual search starts from here if (allFinished || AllThreadsShouldExit) { - lock_release(&WaitLock); + lock_release(&SleepLock[threadID]); break; } // Do sleep here after retesting sleep conditions if (threadID >= ActiveThreads || threads[threadID].state == THREAD_AVAILABLE) - cond_wait(&WaitCond[threadID], &WaitLock); + cond_wait(&SleepCond[threadID], &SleepLock[threadID]); - lock_release(&WaitLock); + lock_release(&SleepLock[threadID]); } // If this thread has been assigned work, launch a search @@ -2308,10 +2308,12 @@ split_point_start: // At split points actual search starts from here // Initialize global locks lock_init(&MPLock); - lock_init(&WaitLock); for (i = 0; i < MAX_THREADS; i++) - cond_init(&WaitCond[i]); + { + lock_init(&SleepLock[i]); + cond_init(&SleepCond[i]); + } // Initialize splitPoints[] locks for (i = 0; i < MAX_THREADS; i++) @@ -2372,12 +2374,14 @@ split_point_start: // At split points actual search starts from here for (int j = 0; j < MAX_ACTIVE_SPLIT_POINTS; j++) lock_destroy(&(threads[i].splitPoints[j].lock)); - lock_destroy(&WaitLock); lock_destroy(&MPLock); // Now we can safely destroy the wait conditions for (int i = 0; i < MAX_THREADS; i++) - cond_destroy(&WaitCond[i]); + { + lock_destroy(&SleepLock[i]); + cond_destroy(&SleepCond[i]); + } } @@ -2565,14 +2569,14 @@ split_point_start: // At split points actual search starts from here } - // wake_sleeping_thread() wakes up all sleeping threads when it is time - // to start a new search from the root. + // wake_sleeping_thread() wakes up the thread with the given threadID + // when it is time to start a new search. void ThreadsManager::wake_sleeping_thread(int threadID) { - lock_grab(&WaitLock); - cond_signal(&WaitCond[threadID]); - lock_release(&WaitLock); + lock_grab(&SleepLock[threadID]); + cond_signal(&SleepCond[threadID]); + lock_release(&SleepLock[threadID]); }