mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Fix a race in pondering mode
Fixes an hang when playing with ponder ON. Perhaps there is still a very small race but now it seems engine does not hang anymore. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
c4517c013c
commit
ffa75215cc
3 changed files with 17 additions and 13 deletions
|
@ -367,9 +367,6 @@ void Search::think() {
|
||||||
// Save "search start" time and reset elapsed time to zero
|
// Save "search start" time and reset elapsed time to zero
|
||||||
elapsed_search_time(get_system_time());
|
elapsed_search_time(get_system_time());
|
||||||
|
|
||||||
// Reset global search signals
|
|
||||||
memset((void*)&Signals, 0, sizeof(Signals));
|
|
||||||
|
|
||||||
// Set output stream mode: normal or chess960. Castling notation is different
|
// Set output stream mode: normal or chess960. Castling notation is different
|
||||||
cout << set960(pos.is_chess960());
|
cout << set960(pos.is_chess960());
|
||||||
|
|
||||||
|
@ -651,6 +648,8 @@ namespace {
|
||||||
// Do we have time for the next iteration? Can we stop searching now?
|
// Do we have time for the next iteration? Can we stop searching now?
|
||||||
if (!Signals.stop && !Signals.stopOnPonderhit && Limits.useTimeManagement())
|
if (!Signals.stop && !Signals.stopOnPonderhit && Limits.useTimeManagement())
|
||||||
{
|
{
|
||||||
|
bool stop = false; // Local variable instead of the volatile Signals.stop
|
||||||
|
|
||||||
// Take in account some extra time if the best move has changed
|
// Take in account some extra time if the best move has changed
|
||||||
if (depth > 4 && depth < 50)
|
if (depth > 4 && depth < 50)
|
||||||
TimeMgr.pv_instability(bestMoveChanges[depth], bestMoveChanges[depth - 1]);
|
TimeMgr.pv_instability(bestMoveChanges[depth], bestMoveChanges[depth - 1]);
|
||||||
|
@ -658,11 +657,11 @@ namespace {
|
||||||
// Stop search if most of available time is already consumed. We probably don't
|
// Stop search if most of available time is already consumed. We probably don't
|
||||||
// have enough time to search the first move at the next iteration anyway.
|
// have enough time to search the first move at the next iteration anyway.
|
||||||
if (elapsed_search_time() > (TimeMgr.available_time() * 62) / 100)
|
if (elapsed_search_time() > (TimeMgr.available_time() * 62) / 100)
|
||||||
Signals.stop = true;
|
stop = true;
|
||||||
|
|
||||||
// Stop search early if one move seems to be much better than others
|
// Stop search early if one move seems to be much better than others
|
||||||
if ( depth >= 10
|
if ( depth >= 10
|
||||||
&& !Signals.stop
|
&& !stop
|
||||||
&& ( bestMoveNeverChanged
|
&& ( bestMoveNeverChanged
|
||||||
|| elapsed_search_time() > (TimeMgr.available_time() * 40) / 100))
|
|| elapsed_search_time() > (TimeMgr.available_time() * 40) / 100))
|
||||||
{
|
{
|
||||||
|
@ -674,14 +673,17 @@ namespace {
|
||||||
(ss+1)->excludedMove = MOVE_NONE;
|
(ss+1)->excludedMove = MOVE_NONE;
|
||||||
|
|
||||||
if (v < rBeta)
|
if (v < rBeta)
|
||||||
Signals.stop = true;
|
stop = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we are allowed to ponder do not stop the search now but keep pondering
|
if (stop)
|
||||||
if (Signals.stop && Limits.ponder) // FIXME Limits.ponder is racy
|
|
||||||
{
|
{
|
||||||
Signals.stop = false;
|
// If we are allowed to ponder do not stop the search now but
|
||||||
Signals.stopOnPonderhit = true;
|
// keep pondering until GUI sends "ponderhit" or "stop".
|
||||||
|
if (Limits.ponder) // FIXME racing
|
||||||
|
Signals.stopOnPonderhit = true;
|
||||||
|
else
|
||||||
|
Signals.stop = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -438,6 +438,9 @@ void ThreadsManager::start_thinking(bool asyncMode) {
|
||||||
while (!main.do_sleep)
|
while (!main.do_sleep)
|
||||||
cond_wait(&sleepCond, &main.sleepLock);
|
cond_wait(&sleepCond, &main.sleepLock);
|
||||||
|
|
||||||
|
// Reset signals before to start the search
|
||||||
|
memset((void*)&Search::Signals, 0, sizeof(Search::Signals));
|
||||||
|
|
||||||
main.do_sleep = false;
|
main.do_sleep = false;
|
||||||
cond_signal(&main.sleepCond); // Wake up main thread
|
cond_signal(&main.sleepCond); // Wake up main thread
|
||||||
|
|
||||||
|
|
|
@ -82,10 +82,9 @@ void uci_loop() {
|
||||||
Search::Limits.ponder = false; // FIXME racing
|
Search::Limits.ponder = false; // FIXME racing
|
||||||
|
|
||||||
if (Search::Signals.stopOnPonderhit)
|
if (Search::Signals.stopOnPonderhit)
|
||||||
{
|
|
||||||
Search::Signals.stop = true;
|
Search::Signals.stop = true;
|
||||||
Threads[0].wake_up(); // In case is waiting for stop or ponderhit
|
|
||||||
}
|
Threads[0].wake_up(); // In case is waiting for stop or ponderhit
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (token == "go")
|
else if (token == "go")
|
||||||
|
|
Loading…
Add table
Reference in a new issue