diff --git a/src/search.cpp b/src/search.cpp index 4eaf2e5e..d86f2493 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -1588,7 +1588,7 @@ void Thread::idle_loop() { // particular we need to avoid a deadlock in case a master thread has, // in the meanwhile, allocated us and sent the wake_up() call before we // had the chance to grab the lock. - if (!is_searching && Threads.sleepWhileIdle) + if (!is_searching && !do_exit) sleepCondition.wait(mutex); mutex.unlock(); diff --git a/src/thread.cpp b/src/thread.cpp index 5f3b4d31..9bd74989 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -76,11 +76,14 @@ void TimerThread::idle_loop() { while (!do_exit) { mutex.lock(); - do sleepCondition.wait_for(mutex, msec ? msec : INT_MAX); - while (!msec && !do_exit); // Don't allow wakeups when msec = 0 + + if (!do_exit) + sleepCondition.wait_for(mutex, msec ? msec : INT_MAX); + mutex.unlock(); - check_time(); + if (msec) + check_time(); } }