while (!thinking && !exit)
{
- Threads.sleepCondition.notify_one(); // Wake up the UI thread if needed
+ sleepCondition.notify_one(); // Wake up the UI thread if needed
sleepCondition.wait(lk);
}
}
+// MainThread::join() waits for main thread to finish the search
+
+void MainThread::join() {
+
+ std::unique_lock<Mutex> lk(mutex);
+ sleepCondition.wait(lk, [&]{ return !thinking; });
+}
+
+
// ThreadPool::init() is called at startup to create and launch requested threads,
// that will go immediately to sleep. We cannot use a c'tor because Threads is a
// static object and we need a fully initialized engine at this point due to
}
-// ThreadPool::wait_for_think_finished() waits for main thread to finish the search
-
-void ThreadPool::wait_for_think_finished() {
-
- std::unique_lock<Mutex> lk(main()->mutex);
- sleepCondition.wait(lk, [&]{ return !main()->thinking; });
-}
-
-
// ThreadPool::start_thinking() wakes up the main thread sleeping in
// MainThread::idle_loop() and starts a new search, then returns immediately.
void ThreadPool::start_thinking(const Position& pos, const LimitsType& limits,
StateStackPtr& states) {
- wait_for_think_finished();
+ main()->join();
SearchTime = now(); // As early as possible