- main()->rootMoves.clear();
- main()->rootPos = pos;
- Limits = limits;
- if (states.get()) // If we don't set a new position, preserve current state
+ // 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)