-// Thread::split() does the actual work of distributing the work at a node between
-// several available threads. If it does not succeed in splitting the node
-// (because no idle threads are available), the function immediately returns.
-// If splitting is possible, a SplitPoint object is initialized with all the
-// data that must be copied to the helper threads and then helper threads are
-// informed that they have been assigned work. This will cause them to instantly
-// leave their idle loops and call search(). When all threads have returned from
-// search() then split() returns.
-
-void Thread::split(Position& pos, Stack* ss, Value alpha, Value beta, Value* bestValue,
- Move* bestMove, Depth depth, int moveCount,
- MovePicker* movePicker, int nodeType, bool cutNode) {
-
- assert(searching);
- assert(-VALUE_INFINITE < *bestValue && *bestValue <= alpha && alpha < beta && beta <= VALUE_INFINITE);
- assert(depth >= Threads.minimumSplitDepth);
- assert(splitPointsSize < MAX_SPLITPOINTS_PER_THREAD);
-
- // Pick and init the next available split point
- SplitPoint& sp = splitPoints[splitPointsSize];
-
- sp.mutex.lock(); // No contention here until we don't increment splitPointsSize
-
- sp.master = this;
- sp.parentSplitPoint = activeSplitPoint;
- sp.slavesMask = 0, sp.slavesMask.set(idx);
- sp.depth = depth;
- sp.bestValue = *bestValue;
- sp.bestMove = *bestMove;
- sp.alpha = alpha;
- sp.beta = beta;
- sp.nodeType = nodeType;
- sp.cutNode = cutNode;
- sp.movePicker = movePicker;
- sp.moveCount = moveCount;
- sp.pos = &pos;
- sp.nodes = 0;
- sp.cutoff = false;
- sp.ss = ss;
- sp.allSlavesSearching = true; // Must be set under lock protection
-
- ++splitPointsSize;
- activeSplitPoint = &sp;
- activePosition = nullptr;
-
- // Try to allocate available threads
- Thread* slave;
-
- while ( sp.slavesMask.count() < MAX_SLAVES_PER_SPLITPOINT
- && (slave = Threads.available_slave(&sp)) != nullptr)
- {
- slave->mutex.lock();