template <bool Fake>
void split(const Position& pos, SearchStack* ss, int ply, Value* alpha, const Value beta, Value* bestValue,
- Depth depth, Move threatMove, bool mateThreat, int* moveCount, MovePicker* mp, bool pvNode);
+ Depth depth, Move threatMove, bool mateThreat, int moveCount, MovePicker* mp, bool pvNode);
private:
friend void poll();
&& !ThreadsMgr.thread_should_stop(threadID)
&& Iteration <= 99)
ThreadsMgr.split<FakeSplit>(pos, ss, ply, &alpha, beta, &bestValue, depth,
- threatMove, mateThreat, &moveCount, &mp, PvNode);
+ threatMove, mateThreat, moveCount, &mp, PvNode);
}
// Step 19. Check for mate and stalemate
if (value > sp->bestValue && !ThreadsMgr.thread_should_stop(threadID))
{
sp->bestValue = value;
-
- if (sp->bestValue > sp->alpha)
+ if (value > sp->alpha)
{
if (!PvNode || value >= sp->beta)
sp->stopRequest = true;
- if (PvNode && value < sp->beta) // This guarantees that always: sp->alpha < sp->beta
+ if (PvNode && value < sp->beta) // We want always sp->alpha < sp->beta
sp->alpha = value;
sp->parentSstack->bestMove = ss->bestMove = move;
void ThreadsManager::exit_threads() {
- ActiveThreads = MAX_THREADS; // HACK
- AllThreadsShouldSleep = true; // HACK
+ ActiveThreads = MAX_THREADS; // Wake up all the threads
+ AllThreadsShouldExit = true; // Let the woken up threads to exit idle_loop()
+ AllThreadsShouldSleep = true; // Avoid an assert in wake_sleeping_threads()
wake_sleeping_threads();
- // This makes the threads to exit idle_loop()
- AllThreadsShouldExit = true;
-
// Wait for thread termination
for (int i = 1; i < MAX_THREADS; i++)
while (threads[i].state != THREAD_TERMINATED) {}
assert(threadID >= 0 && threadID < ActiveThreads);
- SplitPoint* sp;
+ SplitPoint* sp = threads[threadID].splitPoint;
- for (sp = threads[threadID].splitPoint; sp && !sp->stopRequest; sp = sp->parent) {}
+ for ( ; sp && !sp->stopRequest; sp = sp->parent) {}
return sp != NULL;
}
// Make a local copy to be sure doesn't change under our feet
int localActiveSplitPoints = threads[slave].activeSplitPoints;
- if (localActiveSplitPoints == 0)
- // No active split points means that the thread is available as
- // a slave for any other thread.
- return true;
-
- if (ActiveThreads == 2)
+ // No active split points means that the thread is available as
+ // a slave for any other thread.
+ if (localActiveSplitPoints == 0 || ActiveThreads == 2)
return true;
// Apply the "helpful master" concept if possible. Use localActiveSplitPoints
template <bool Fake>
void ThreadsManager::split(const Position& p, SearchStack* ss, int ply, Value* alpha,
const Value beta, Value* bestValue, Depth depth, Move threatMove,
- bool mateThreat, int* moveCount, MovePicker* mp, bool pvNode) {
+ bool mateThreat, int moveCount, MovePicker* mp, bool pvNode) {
assert(p.is_ok());
assert(ply > 0 && ply < PLY_MAX);
assert(*bestValue >= -VALUE_INFINITE);
splitPoint.pvNode = pvNode;
splitPoint.bestValue = *bestValue;
splitPoint.mp = mp;
- splitPoint.moveCount = *moveCount;
+ splitPoint.moveCount = moveCount;
splitPoint.pos = &p;
splitPoint.parentSstack = ss;
for (i = 0; i < ActiveThreads; i++)