mirror of
https://github.com/sockspls/badfish
synced 2025-07-11 19:49:14 +00:00
Simplify finished search in ponder/infinite mode.
In this rare case (e.g. go infinite on a stalemate), just spin till ponderhit/stop comes. The Thread::wait() is a renmant of the old YBWC code, today with lazy SMP, threads don't need to wait when outside of their idle loop. No functional change.
This commit is contained in:
parent
66c5eaebd8
commit
2783203428
4 changed files with 10 additions and 25 deletions
|
@ -277,13 +277,13 @@ void MainThread::search() {
|
||||||
// the UCI protocol states that we shouldn't print the best move before the
|
// the UCI protocol states that we shouldn't print the best move before the
|
||||||
// GUI sends a "stop" or "ponderhit" command. We therefore simply wait here
|
// GUI sends a "stop" or "ponderhit" command. We therefore simply wait here
|
||||||
// until the GUI sends one of those commands (which also raises Threads.stop).
|
// until the GUI sends one of those commands (which also raises Threads.stop).
|
||||||
if (!Threads.stop && (Threads.ponder || Limits.infinite))
|
|
||||||
{
|
|
||||||
Threads.stopOnPonderhit = true;
|
Threads.stopOnPonderhit = true;
|
||||||
wait(Threads.stop);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stop the threads if not already stopped
|
while (!Threads.stop && (Threads.ponder || Limits.infinite))
|
||||||
|
{} // Busy wait for a stop or a ponder reset
|
||||||
|
|
||||||
|
// Stop the threads if not already stopped (also raise the stop if
|
||||||
|
// "ponderhit" just reset Threads.ponder).
|
||||||
Threads.stop = true;
|
Threads.stop = true;
|
||||||
|
|
||||||
// Wait until all threads have finished
|
// Wait until all threads have finished
|
||||||
|
|
|
@ -68,24 +68,12 @@ void Thread::wait_for_search_finished() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Thread::wait() waits on sleep condition until condition is true
|
|
||||||
|
|
||||||
void Thread::wait(std::atomic_bool& condition) {
|
|
||||||
|
|
||||||
std::unique_lock<Mutex> lk(mutex);
|
|
||||||
sleepCondition.wait(lk, [&]{ return bool(condition); });
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Thread::start_searching() wakes up the thread that will start the search
|
/// Thread::start_searching() wakes up the thread that will start the search
|
||||||
|
|
||||||
void Thread::start_searching(bool resume) {
|
void Thread::start_searching() {
|
||||||
|
|
||||||
std::unique_lock<Mutex> lk(mutex);
|
std::unique_lock<Mutex> lk(mutex);
|
||||||
|
|
||||||
if (!resume)
|
|
||||||
searching = true;
|
searching = true;
|
||||||
|
|
||||||
sleepCondition.notify_one();
|
sleepCondition.notify_one();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,9 +52,8 @@ public:
|
||||||
virtual ~Thread();
|
virtual ~Thread();
|
||||||
virtual void search();
|
virtual void search();
|
||||||
void idle_loop();
|
void idle_loop();
|
||||||
void start_searching(bool resume = false);
|
void start_searching();
|
||||||
void wait_for_search_finished();
|
void wait_for_search_finished();
|
||||||
void wait(std::atomic_bool& condition);
|
|
||||||
|
|
||||||
Pawns::Table pawnsTable;
|
Pawns::Table pawnsTable;
|
||||||
Material::Table materialTable;
|
Material::Table materialTable;
|
||||||
|
|
|
@ -176,10 +176,8 @@ void UCI::loop(int argc, char* argv[]) {
|
||||||
if ( token == "quit"
|
if ( token == "quit"
|
||||||
|| token == "stop"
|
|| token == "stop"
|
||||||
|| (token == "ponderhit" && Threads.stopOnPonderhit))
|
|| (token == "ponderhit" && Threads.stopOnPonderhit))
|
||||||
{
|
|
||||||
Threads.stop = true;
|
Threads.stop = true;
|
||||||
Threads.main()->start_searching(true); // Could be sleeping
|
|
||||||
}
|
|
||||||
else if (token == "ponderhit")
|
else if (token == "ponderhit")
|
||||||
Threads.ponder = false; // Switch to normal search
|
Threads.ponder = false; // Switch to normal search
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue