- Threads.mutex.unlock();
-
- Stack stack[MAX_PLY_PLUS_6], *ss = stack+2; // To allow referencing (ss-2)
- Position pos(*sp->pos, this);
-
- std::memcpy(ss-2, sp->ss-2, 5 * sizeof(Stack));
- ss->splitPoint = sp;
-
- sp->mutex.lock();
-
- assert(activePosition == NULL);
-
- activePosition = &pos;
-
- switch (sp->nodeType) {
- case Root:
- search<SplitPointRoot>(pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode);
- break;
- case PV:
- search<SplitPointPV>(pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode);
- break;
- case NonPV:
- search<SplitPointNonPV>(pos, ss, sp->alpha, sp->beta, sp->depth, sp->cutNode);
- break;
- default:
- assert(false);
- }
-
- assert(searching);
-
- searching = false;
- activePosition = NULL;
- sp->slavesMask &= ~(1ULL << idx);
- sp->nodes += pos.nodes_searched();
-
- // Wake up the master thread so to allow it to return from the idle
- // loop in case we are the last slave of the split point.
- if ( Threads.sleepWhileIdle
- && this != sp->masterThread
- && !sp->slavesMask)
- {
- assert(!sp->masterThread->searching);
- sp->masterThread->notify_one();
- }
-
- // After releasing the lock we can't access any SplitPoint related data
- // in a safe way because it could have been released under our feet by
- // the sp master. Also accessing other Thread objects is unsafe because
- // if we are exiting there is a chance that they are already freed.
- sp->mutex.unlock();
- }
-
- // If this thread is the master of a split point and all slaves have finished
- // their work at this split point, return from the idle loop.
- if (this_sp && !this_sp->slavesMask)
- {
- this_sp->mutex.lock();
- bool finished = !this_sp->slavesMask; // Retest under lock protection
- this_sp->mutex.unlock();
- if (finished)
- return;
- }
- }
-}
-
-
-/// check_time() is called by the timer thread when the timer triggers. It is
-/// used to print debug info and, more importantly, to detect when we are out of
-/// available time and thus stop the search.
-
-void check_time() {
-
- static Time::point lastInfoTime = Time::now();
- int64_t nodes = 0; // Workaround silly 'uninitialized' gcc warning
-
- if (Time::now() - lastInfoTime >= 1000)
- {
- lastInfoTime = Time::now();
- dbg_print();