- do_sleep = true; // Always return to sleep after a search
- is_searching = false;
-
- while (do_sleep && !do_terminate)
- {
- cond_signal(&Threads.sleepCond); // Wake up UI thread if needed
- cond_wait(&sleepCond, &sleepLock);
- }
-
- is_searching = true;
-
- lock_release(&sleepLock);
-
- if (do_terminate)
- return;
-
- think(); // This is the search entry point
- }
-}
-
-
-// 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 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);