UCI-rework endgame
I decided to throw the multithreaded idea in the bin and go for an implementation similar to what HGM suggested in
another topic .
As said earlier today, I have gotten the (direct) Vice influence down to one function (the InputWaiting one), which Bluefever got from
another place himself. I therefore think this is acceptable, and the input parsing while searching is now the following:
Every 2047 nodes, I check for an aborted search with the following method:
Code: Select all
// The checkup function sees if we need to stop the search
void check_stopped_search(SearchThread_t* ss) {
// Only the 0'th (main) thread should check if the UCI has sent us commands to quit.
if (ss->thread_id == 0) {
if (ss->info->timeset && getTimeMs() >= ss->info->stoptime) {
ss->info->stopped = true;
}
ReadInput(ss->info->stopped, ss->info->quit);
// We've been told to stop, so let's tell the other threads.
if (ss->info->stopped) {
Search::isStop = true;
}
}
// All the other threads will check if the time has expired or the main thread has set the isStop flag.
else {
if (ss->info->timeset && getTimeMs() >= ss->info->stoptime) {
ss->info->stopped = true;
}
// See if the main thread has told us to stop searching.
if (Search::isStop.load(std::memory_order_relaxed)) {
ss->info->stopped = true;
}
}
}
Where the ReadInput method is the following:
Code: Select all
void ReadInput(bool& isStop, bool& isQuit) {
if (InputWaiting()) {
isStop = true;
std::string input = "";
std::getline(std::cin, input);
if (input.find("quit") != std::string::npos) {
isQuit = true;
}
}
}
Thus, when we run the check_stopped_search method, we check for a timeout. If we're the main thread, we read the stdin for pending input and parse it. If the GUI has told us to stop, we'll tell all other threads by setting the std::atomic<bool> isStop flag.
Now on to cleaning up the UCI-rework, testing for bugs one last time and finally some search improvements again!