void get_beta_counters(Color us, int64_t& our, int64_t& their) const;
bool idle_thread_exists(int master) const;
bool thread_is_available(int slave, int master) const;
- bool thread_should_stop(int threadID);
+ bool thread_should_stop(int threadID) const;
void wake_sleeping_threads();
void put_threads_to_sleep();
void idle_loop(int threadID, SplitPoint* waitSp);
/* Here we have the lock still grabbed */
// If this is the master thread and we have been asked to stop because of
- // a beta cutoff higher up in the tree, stop all slave threads.
+ // a beta cutoff higher up in the tree, stop all slave threads. Note that
+ // thread_should_stop(threadID) does not imply that 'stop' flag is set, so
+ // do this explicitly now, under lock protection.
if (sp->master == threadID && TM.thread_should_stop(threadID))
for (int i = 0; i < TM.active_threads(); i++)
- if (sp->slaves[i])
+ if (sp->slaves[i] || i == threadID)
TM.set_stop_request(i);
sp->cpus--;
/* Here we have the lock still grabbed */
// If this is the master thread and we have been asked to stop because of
- // a beta cutoff higher up in the tree, stop all slave threads.
+ // a beta cutoff higher up in the tree, stop all slave threads. Note that
+ // thread_should_stop(threadID) does not imply that 'stop' flag is set, so
+ // do this explicitly now, under lock protection.
if (sp->master == threadID && TM.thread_should_stop(threadID))
for (int i = 0; i < TM.active_threads(); i++)
- if (sp->slaves[i])
+ if (sp->slaves[i] || i == threadID)
TM.set_stop_request(i);
sp->cpus--;
// cutoff has occurred in the thread's currently active split point, or in
// some ancestor of the current split point.
- bool ThreadsManager::thread_should_stop(int threadID) {
+ bool ThreadsManager::thread_should_stop(int threadID) const {
assert(threadID >= 0 && threadID < ActiveThreads);
for (sp = threads[threadID].splitPoint; sp != NULL; sp = sp->parent)
if (sp->finished)
- {
- threads[threadID].stop = true;
return true;
- }
return false;
}
AllThreadsShouldSleep = true;
- // Wait for the threads to be all sleeping
+ // Wait for the threads to be all sleeping and reset flags
+ // to a known state.
for (int i = 1; i < ActiveThreads; i++)
+ {
while (!threads[i].sleeping);
- }
+ assert(threads[i].idle);
+ assert(threads[i].running);
+ assert(!threads[i].workIsWaiting);
+
+ // These two flags can be in a random state
+ threads[i].stop = threads[i].printCurrentLineRequest = false;
+ }
+ }
// print_current_line() prints _once_ the current line of search for a
// given thread and then setup the print request for the next thread.