// If this thread has been assigned work, launch a search
while (searching)
{
- Threads.mutex.lock();
+ mutex.lock();
assert(activeSplitPoint);
-
SplitPoint* sp = activeSplitPoint;
- Threads.mutex.unlock();
+ mutex.unlock();
Stack stack[MAX_PLY+4], *ss = stack+2; // To allow referencing (ss-2) and (ss+2)
Position pos(*sp->pos, this);
sp = bestSp;
// Recheck the conditions under lock protection
- Threads.mutex.lock();
sp->mutex.lock();
if ( sp->allSlavesSearching
- && sp->slavesMask.count() < MAX_SLAVES_PER_SPLITPOINT
- && can_join(sp))
+ && sp->slavesMask.count() < MAX_SLAVES_PER_SPLITPOINT)
{
- sp->slavesMask.set(idx);
- activeSplitPoint = sp;
- searching = true;
+ mutex.lock();
+
+ if (can_join(sp))
+ {
+ sp->slavesMask.set(idx);
+ activeSplitPoint = sp;
+ searching = true;
+ }
+
+ mutex.unlock();
}
sp->mutex.unlock();
- Threads.mutex.unlock();
}
}
else if (Limits.nodes)
{
- Threads.mutex.lock();
-
int64_t nodes = RootPos.nodes_searched();
// Loop across all split points and sum accumulated SplitPoint nodes plus
// all the currently active positions nodes.
+ // FIXME: Racy...
for (Thread* th : Threads)
for (size_t i = 0; i < th->splitPointsSize; ++i)
{
sp.mutex.unlock();
}
- Threads.mutex.unlock();
-
if (nodes >= Limits.nodes)
Signals.stop = true;
}