From 232c50fed0b80a0f39322a925575f760648ae0a5 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Mon, 14 Aug 2017 09:12:16 -0700 Subject: [PATCH] Fix incorrect StateInfo We use Position::set() to set root position across threads. But there are some StateInfo fields (previous, pliesFromNull, capturedPiece) that cannot be deduced from a fen string, so set() clears them and to not lose the info we need to backup and later restore setupStates->back(). Note that setupStates is shared by threads but is accessed in read-only mode. This fixes regression introduced by df6cb446eaf21 Tested with 3 threads at STC: LLR: 2.95 (-2.94,2.94) [-4.00,0.00] Total: 14436 W: 2304 L: 2196 D: 9936 Bench: 5608839 --- src/thread.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/thread.cpp b/src/thread.cpp index d358dec3..208cb0b1 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -158,10 +158,12 @@ void ThreadPool::start_thinking(Position& pos, StateListPtr& states, if (states.get()) setupStates = std::move(states); // Ownership transfer, states is now empty - // We use Position::set() to set root position across threads. So we - // need to save and later to restore st->previous, cleared by set(). - // Note that setupStates is shared by threads but is accessed in read-only mode. - StateInfo* previous = setupStates->back().previous; + // We use Position::set() to set root position across threads. But there are + // some StateInfo fields (previous, pliesFromNull, capturedPiece) that cannot + // be deduced from a fen string, so set() clears them and to not lose the info + // we need to backup and later restore setupStates->back(). Note that setupStates + // is shared by threads but is accessed in read-only mode. + StateInfo tmp = setupStates->back(); for (Thread* th : Threads) { @@ -171,7 +173,7 @@ void ThreadPool::start_thinking(Position& pos, StateListPtr& states, th->rootPos.set(pos.fen(), pos.is_chess960(), &setupStates->back(), th); } - setupStates->back().previous = previous; + setupStates->back() = tmp; main()->start_searching(); } -- 2.39.2