]> git.sesse.net Git - stockfish/commitdiff
Fix race while exiting
authorMarco Costalba <mcostalba@gmail.com>
Wed, 16 Jan 2013 08:26:10 +0000 (09:26 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Wed, 16 Jan 2013 18:58:55 +0000 (19:58 +0100)
Fix again TimerThread::idle_loop() to prevent a
theoretical race with 'exit' flag in ~Thread().

Indeed in Thread d'tor we raise 'exit' and then
call notify() that is lock protected, so we
have to check again for 'exit' before going to
sleep in idle_loop().

Also same change in Thread::idle_loop() where we
now check for 'exit' before to go to sleep.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/search.cpp
src/thread.cpp

index 4eaf2e5ee07c2caea5ce159be013a68a6451d94c..d86f249365f8ed318f70359541fff404862f8cf2 100644 (file)
@@ -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();
index 5f3b4d314bfb2b6edf27d65dec92b47d6dfafa96..9bd7498979761942ba0b0e01f315e2c444385c26 100644 (file)
@@ -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();
   }
 }