- if (do_terminate)
- return;
-
- Search::think();
- }
-}
-
-
-// ThreadsManager::start_thinking() is used by UI thread to wake up the main
-// thread parked in main_loop() and starting a new search. If asyncMode is true
-// then function returns immediately, otherwise caller is blocked waiting for
-// the search to finish.
-
-void ThreadsManager::start_thinking(const Position& pos, const Search::LimitsType& limits,
- const std::vector<Move>& searchMoves, bool asyncMode) {
- Thread& main = threads[0];
-
- lock_grab(&main.sleepLock);
-
- // Wait main thread has finished before to launch a new search
- while (!main.do_sleep)
- cond_wait(&sleepCond, &main.sleepLock);
-
- // Copy input arguments to Search global variables
- Search::RootPosition.copy(pos, 0);
- Search::Limits = limits;
- Search::RootMoves = searchMoves;
-
- // Reset signals before to start the search
- memset((void*)&Search::Signals, 0, sizeof(Search::Signals));
-
- main.do_sleep = false;
- cond_signal(&main.sleepCond); // Wake up main thread
-
- if (!asyncMode)
- cond_wait(&sleepCond, &main.sleepLock);
-
- lock_release(&main.sleepLock);
+ Thread* t = main_thread();
+ lock_grab(t->sleepLock);
+ cond_signal(t->sleepCond); // In case is waiting for stop or ponderhit
+ while (!t->do_sleep) cond_wait(sleepCond, t->sleepLock);
+ lock_release(t->sleepLock);