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