]> git.sesse.net Git - stockfish/commitdiff
Don't lock before check for termination
authorMarco Costalba <mcostalba@gmail.com>
Wed, 14 Sep 2011 05:16:46 +0000 (06:16 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 24 Sep 2011 16:12:36 +0000 (17:12 +0100)
Restore old locking scheme changed with
commit 1e92df6b20aa2240.

This seems to prevent a very rare crash that occurs
once every 5-10K games.

With this patch we have no crashes after 33K games.

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

index 0f2373cd28fd28838c1e79990c5d26349ae554a2..4408475341ac9deea60df927609c4bfd61e79ae0 100644 (file)
@@ -2158,17 +2158,16 @@ void Thread::idle_loop(SplitPoint* sp) {
       {
           assert((!sp && threadID) || Threads.use_sleeping_threads());
 
       {
           assert((!sp && threadID) || Threads.use_sleeping_threads());
 
-          // Grab the lock to avoid races with Thread::wake_up()
-          lock_grab(&sleepLock);
-
           // Slave thread should exit as soon as do_terminate flag raises
           if (do_terminate)
           {
               assert(!sp);
           // Slave thread should exit as soon as do_terminate flag raises
           if (do_terminate)
           {
               assert(!sp);
-              lock_release(&sleepLock);
               return;
           }
 
               return;
           }
 
+          // Grab the lock to avoid races with Thread::wake_up()
+          lock_grab(&sleepLock);
+
           // If we are master and all slaves have finished don't go to sleep
           if (sp && all_slaves_finished(sp))
           {
           // If we are master and all slaves have finished don't go to sleep
           if (sp && all_slaves_finished(sp))
           {