Rework lock protecting
[stockfish] / src / search.cpp
index 54a9ec878c44f5b617a30fbc85280de160f49628..9ff447beb6e0a873cc0b5252927175d0a476bb29 100644 (file)
@@ -1622,11 +1622,15 @@ void Thread::idle_loop() {
           else
               assert(false);
 
-          spinlock.acquire();
           assert(searching);
 
+          spinlock.acquire();
+
           searching = false;
           activePosition = nullptr;
+
+          spinlock.release();
+
           sp->slavesMask.reset(idx);
           sp->allSlavesSearching = false;
           sp->nodes += pos.nodes_searched();
@@ -1634,7 +1638,6 @@ void Thread::idle_loop() {
           // After releasing the lock we can't access any SplitPoint related data
           // in a safe way because it could have been released under our feet by
           // the sp master.
-          spinlock.release();
           sp->spinlock.release();
 
           // Try to late join to another split point if none of its slaves has