]> git.sesse.net Git - stockfish/commitdiff
Fix a bug in timer loop
authorMarco Costalba <mcostalba@gmail.com>
Mon, 14 Jan 2013 18:32:30 +0000 (19:32 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Mon, 14 Jan 2013 18:32:30 +0000 (19:32 +0100)
Silly logic bug introduced in dda7de17e74d7e8

Timer thread, when msec = 0, instead of going
to sleep, calls check_time() in an endless loop.

Spotted and reported by snino64 due to abnormally
high CPU usage.

No functional change.

src/thread.cpp

index bc0b3fcc3227b3a5c128256eafed6bf0852ad1e4..5f3b4d314bfb2b6edf27d65dec92b47d6dfafa96 100644 (file)
@@ -76,9 +76,10 @@ void TimerThread::idle_loop() {
   while (!do_exit)
   {
       mutex.lock();
-      while (!msec && !do_exit)
-          sleepCondition.wait_for(mutex, msec ? msec : INT_MAX);
+      do sleepCondition.wait_for(mutex, msec ? msec : INT_MAX);
+      while (!msec && !do_exit); // Don't allow wakeups when msec = 0
       mutex.unlock();
+
       check_time();
   }
 }