assert(value > -VALUE_INFINITE && value < VALUE_INFINITE);
- if (TM.thread_should_stop(threadID))
- {
- lock_grab(&(sp->lock));
- break;
- }
-
// New best move?
if (value > sp->bestValue) // Less then 2% of cases
{
- // Recursive locking, lock current split point and its ancestors to
- // guarantee thread_should_stop() and sp_update_pv() are race free.
- SplitPoint* spChain[MAX_THREADS * ACTIVE_SPLIT_POINTS_MAX];
- int cnt = 0;
- for (spChain[cnt] = sp; spChain[cnt]; )
- {
- lock_grab(&(spChain[cnt++]->lock));
- spChain[cnt] = spChain[cnt - 1]->parent;
- }
-
+ lock_grab(&(sp->lock));
if (value > sp->bestValue && !TM.thread_should_stop(threadID))
{
sp->bestValue = value;
sp_update_pv(sp->parentSstack, ss, sp->ply);
}
}
-
- // Release locks in reverse order
- while (cnt > 0)
- lock_release(&(spChain[--cnt]->lock));
+ lock_release(&(sp->lock));
}
}
assert(value > -VALUE_INFINITE && value < VALUE_INFINITE);
- if (TM.thread_should_stop(threadID))
- {
- lock_grab(&(sp->lock));
- break;
- }
-
// New best move?
if (value > sp->bestValue) // Less then 2% of cases
{
- // Recursive locking, lock current split point and its ancestors to
- // guarantee thread_should_stop() and sp_update_pv() are race free.
- SplitPoint* spChain[MAX_THREADS * ACTIVE_SPLIT_POINTS_MAX];
- int cnt = 0;
- for (spChain[cnt] = sp; spChain[cnt]; )
- {
- lock_grab(&(spChain[cnt++]->lock));
- spChain[cnt] = spChain[cnt - 1]->parent;
- }
-
+ lock_grab(&(sp->lock));
if (value > sp->bestValue && !TM.thread_should_stop(threadID))
{
sp->bestValue = value;
ss[sp->ply].mateKiller = move;
}
}
-
- // Release locks in reverse order
- while (cnt > 0)
- lock_release(&(spChain[--cnt]->lock));
+ lock_release(&(sp->lock));
}
}
// If this thread has been assigned work, launch a search
if (threads[threadID].state == THREAD_WORKISWAITING)
{
+ assert(!AllThreadsShouldExit);
+
threads[threadID].state = THREAD_SEARCHING;
if (threads[threadID].splitPoint->pvNode)
assert(threads[threadID].state == THREAD_SEARCHING);
- // If this is a slave thread reset to available, instead
- // if it is a master thread and all slaves have finished
- // then leave as is to avoid booking by another master,
- // we will leave idle loop shortly anyhow.
- if ( !AllThreadsShouldExit
- && (!waitSp || waitSp->cpus > 0))
- threads[threadID].state = THREAD_AVAILABLE;
+ threads[threadID].state = THREAD_AVAILABLE;
}
// If this thread is the master of a split point and all threads have
lock_init(&IOLock, NULL);
// Initialize SplitPointStack locks
- for (int i = 0; i < MAX_THREADS; i++)
+ for (i = 0; i < MAX_THREADS; i++)
for (int j = 0; j < ACTIVE_SPLIT_POINTS_MAX; j++)
{
SplitPointStack[i][j].parent = NULL;
}
// Pick the next available split point object from the split point stack
- splitPoint = SplitPointStack[master] + threads[master].activeSplitPoints;
- threads[master].activeSplitPoints++;
+ splitPoint = &SplitPointStack[master][threads[master].activeSplitPoints];
// Initialize the split point object
splitPoint->parent = threads[master].splitPoint;
splitPoint->slaves[i] = 0;
threads[master].splitPoint = splitPoint;
+ threads[master].activeSplitPoints++;
// If we are here it means we are not available
assert(threads[master].state != THREAD_AVAILABLE);