mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 00:33:09 +00:00
Recursive lock all split point's chain
When we found a cut-off then lock all the split point chain, not only current one to avoid races in case two threads running on different split points where one is ancestor then the other, find a beta cut-off at the same time, in this case we want only one to call sp_update_pv(). No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
2da290d72b
commit
512a4e4ff0
1 changed files with 29 additions and 5 deletions
|
@ -1860,17 +1860,29 @@ namespace {
|
|||
// New best move?
|
||||
if (value > sp->bestValue) // Less then 2% of cases
|
||||
{
|
||||
lock_grab(&(sp->lock));
|
||||
// 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;
|
||||
}
|
||||
|
||||
if (value > sp->bestValue && !TM.thread_should_stop(threadID))
|
||||
{
|
||||
sp->bestValue = value;
|
||||
if (sp->bestValue >= sp->beta)
|
||||
{
|
||||
sp_update_pv(sp->parentSstack, ss, sp->ply);
|
||||
sp->stopRequest = true;
|
||||
sp_update_pv(sp->parentSstack, ss, sp->ply);
|
||||
}
|
||||
}
|
||||
lock_release(&(sp->lock));
|
||||
|
||||
// Release locks in reverse order
|
||||
while (cnt > 0)
|
||||
lock_release(&(spChain[--cnt]->lock));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1975,7 +1987,16 @@ namespace {
|
|||
// New best move?
|
||||
if (value > sp->bestValue) // Less then 2% of cases
|
||||
{
|
||||
lock_grab(&(sp->lock));
|
||||
// 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;
|
||||
}
|
||||
|
||||
if (value > sp->bestValue && !TM.thread_should_stop(threadID))
|
||||
{
|
||||
sp->bestValue = value;
|
||||
|
@ -1992,7 +2013,10 @@ namespace {
|
|||
ss[sp->ply].mateKiller = move;
|
||||
}
|
||||
}
|
||||
lock_release(&(sp->lock));
|
||||
|
||||
// Release locks in reverse order
|
||||
while (cnt > 0)
|
||||
lock_release(&(spChain[--cnt]->lock));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue