From 2da3c1a67def3f0a616c682bd0222e5422133594 Mon Sep 17 00:00:00 2001 From: rn5f107s2 Date: Tue, 25 Jun 2024 20:53:58 +0200 Subject: [PATCH] Avoid reading old nodecounts in multithreading Previously if the thread with id zero finished search before any of the other threads had reset their nodecount, the previous nodecount was read, this fixes this behaviour by clearing nodecounts of all threads before starting search bench 5022919 --- src/thread.cpp | 11 +++++++++-- src/thread.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/thread.cpp b/src/thread.cpp index 376fe3d..94707d4 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -18,6 +18,11 @@ void Thread::clear() { state.clearHistory(); } +void Thread::initSearchInfo(SearchTime st) { + state.si.clear(); + state.si.st = st; +} + void Thread::detach() { thread.detach(); } @@ -36,9 +41,11 @@ u64 Thread::nodes() { void ThreadPool::start(Position &pos, SearchTime &st, int depth) { // Before starting the threads set all of them to searching, to avoid the mainthread stopping search - // while other threads havent been started yet - for (auto &t : threads) + // while other threads havent been started yet, also reset SearchInfo here, to avoid reading old nodecounts + for (auto &t : threads) { t.searching.store(true, std::memory_order_relaxed); + t.initSearchInfo(st); + } for (auto &t : threads) t.start(pos, st, depth); diff --git a/src/thread.h b/src/thread.h index db84c1f..987ebb7 100644 --- a/src/thread.h +++ b/src/thread.h @@ -23,6 +23,7 @@ class Thread { void join(); void stop(); void clear(); + void initSearchInfo(SearchTime st); void detach(); bool done(); int id() const;