mirror of
https://github.com/sockspls/badfish
synced 2025-05-02 01:29:36 +00:00
Fix some races in SMP code
When a search fails high then sp->alpha is increased and slave threads are requested to stop. So we have to check for a stop request before to start a search otherwise we could end up with sp->alpha >= sp->beta leading to an assert in debug run in search_pv(). This patch fixes the assert and get rid of some of possible races. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
eb6ddd54f1
commit
3975a2b94f
1 changed files with 15 additions and 6 deletions
|
@ -2009,7 +2009,14 @@ namespace {
|
||||||
if (sp->ply == 1 && RootMoveNumber == 1)
|
if (sp->ply == 1 && RootMoveNumber == 1)
|
||||||
Threads[threadID].failHighPly1 = true;
|
Threads[threadID].failHighPly1 = true;
|
||||||
|
|
||||||
value = -search_pv(pos, ss, -sp->beta, -sp->alpha, newDepth, sp->ply+1, threadID);
|
// If another thread has failed high then sp->alpha has been increased
|
||||||
|
// to be higher or equal then beta, if so, avoid to start a PV search.
|
||||||
|
localAlpha = sp->alpha;
|
||||||
|
if (localAlpha < sp->beta)
|
||||||
|
value = -search_pv(pos, ss, -sp->beta, -localAlpha, newDepth, sp->ply+1, threadID);
|
||||||
|
else
|
||||||
|
assert(thread_should_stop(threadID));
|
||||||
|
|
||||||
Threads[threadID].failHighPly1 = false;
|
Threads[threadID].failHighPly1 = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2027,11 +2034,7 @@ namespace {
|
||||||
sp->bestValue = value;
|
sp->bestValue = value;
|
||||||
if (value > sp->alpha)
|
if (value > sp->alpha)
|
||||||
{
|
{
|
||||||
sp->alpha = value;
|
// Ask threads to stop before to modify sp->alpha
|
||||||
sp_update_pv(sp->parentSstack, ss, sp->ply);
|
|
||||||
if (value == value_mate_in(sp->ply + 1))
|
|
||||||
ss[sp->ply].mateKiller = move;
|
|
||||||
|
|
||||||
if (value >= sp->beta)
|
if (value >= sp->beta)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < ActiveThreads; i++)
|
for (int i = 0; i < ActiveThreads; i++)
|
||||||
|
@ -2040,6 +2043,12 @@ namespace {
|
||||||
|
|
||||||
sp->finished = true;
|
sp->finished = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sp->alpha = value;
|
||||||
|
|
||||||
|
sp_update_pv(sp->parentSstack, ss, sp->ply);
|
||||||
|
if (value == value_mate_in(sp->ply + 1))
|
||||||
|
ss[sp->ply].mateKiller = move;
|
||||||
}
|
}
|
||||||
// If we are at ply 1, and we are searching the first root move at
|
// If we are at ply 1, and we are searching the first root move at
|
||||||
// ply 0, set the 'Problem' variable if the score has dropped a lot
|
// ply 0, set the 'Problem' variable if the score has dropped a lot
|
||||||
|
|
Loading…
Add table
Reference in a new issue