X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fsearch.cpp;h=6ea5e3a261ffe1c6453dab650c4ab836417199b9;hp=08a779565289767d1fa56b63e03671d77ac970fe;hb=9a6cfee73bbad3051f888e6b8f8e88293763bf70;hpb=a4b2eeea759f10ca1ce864c2a30a990a9a991aa9 diff --git a/src/search.cpp b/src/search.cpp index 08a77956..6ea5e3a2 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -278,10 +278,13 @@ void Search::think() { } for (Thread* th : Threads) + { th->maxPly = 0; + th->notify_one(); // Wake up all the threads + } Threads.timer->run = true; - Threads.timer->notify_one(); // Wake up the recurring timer + Threads.timer->notify_one(); // Start the recurring timer id_loop(RootPos); // Let's start searching ! @@ -1591,34 +1594,17 @@ void Thread::idle_loop() { assert(!this_sp || (this_sp->master == this && searching)); - while ( !exit - && !(this_sp && this_sp->slavesMask.none())) + while (!exit && !(this_sp && this_sp->slavesMask.none())) { - // If there is nothing to do, sleep. - while( !exit - && !(this_sp && this_sp->slavesMask.none()) - && !searching) - { - if ( !this_sp - && !Threads.main()->thinking) - { - std::unique_lock lk(mutex); - while (!exit && !Threads.main()->thinking) - sleepCondition.wait(lk); - } - else - std::this_thread::yield(); - } - // If this thread has been assigned work, launch a search while (searching) { - mutex.lock(); + spinlock.acquire(); assert(activeSplitPoint); SplitPoint* sp = activeSplitPoint; - mutex.unlock(); + spinlock.release(); Stack stack[MAX_PLY+4], *ss = stack+2; // To allow referencing (ss-2) and (ss+2) Position pos(*sp->pos, this); @@ -1715,6 +1701,18 @@ void Thread::idle_loop() { sp->spinlock.release(); } } + + // If search is finished then sleep, otherwise just yield + if (!Threads.main()->thinking) + { + assert(!this_sp); + + std::unique_lock lk(mutex); + while (!exit && !Threads.main()->thinking) + sleepCondition.wait(lk); + } + else + std::this_thread::yield(); // Wait for a new job or for our slaves to finish } }