- // Pick the next available split point object from the split point stack
- SplitPoint& splitPoint = masterThread.splitPoints[masterThread.activeSplitPoints++];
-
- // Initialize the split point object
- splitPoint.parent = masterThread.splitPoint;
- splitPoint.master = master;
- splitPoint.is_betaCutoff = false;
- splitPoint.depth = depth;
- splitPoint.threatMove = threatMove;
- splitPoint.alpha = *alpha;
- splitPoint.beta = beta;
- splitPoint.pvNode = pvNode;
- splitPoint.bestValue = *bestValue;
- splitPoint.mp = mp;
- splitPoint.moveCount = moveCount;
- splitPoint.pos = &pos;
- splitPoint.nodes = 0;
- splitPoint.ss = ss;
- for (i = 0; i < activeThreads; i++)
- splitPoint.is_slave[i] = false;
-
- masterThread.splitPoint = &splitPoint;
-
- // If we are here it means we are not available
- assert(masterThread.state != Thread::AVAILABLE);
-
- int workersCnt = 1; // At least the master is included
-
- // Allocate available threads setting state to THREAD_BOOKED
- for (i = 0; !Fake && i < activeThreads && workersCnt < maxThreadsPerSplitPoint; i++)
- if (i != master && threads[i].is_available_to(master))
- {
- threads[i].state = Thread::BOOKED;
- threads[i].splitPoint = &splitPoint;
- splitPoint.is_slave[i] = true;
- workersCnt++;
- }
+ // We have returned from the idle loop, which means that all threads are
+ // finished. Note that setting is_searching and decreasing splitPointsCnt is
+ // done under lock protection to avoid a race with Thread::is_available_to().
+ lock_grab(sp->lock); // To protect sp->nodes
+ lock_grab(splitLock);