X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fthread.cpp;h=1217e3ab020656787c9dd1b8a5886fecdadcaa1a;hp=c25fc129cd4ef0bc570e9377ecfe63765e8fb294;hb=38112060dc2da351c6dde8f12d0ee5cfaeac5084;hpb=1277a428237eec3299c6606951fac014bb3ef851 diff --git a/src/thread.cpp b/src/thread.cpp index c25fc129..1217e3ab 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -81,7 +81,8 @@ void ThreadBase::wait_for(volatile const bool& condition) { Thread::Thread() /* : splitPoints() */ { // Initialization of non POD broken in MSVC searching = false; - maxPly = splitPointsSize = 0; + maxPly = 0; + splitPointsSize = 0; activeSplitPoint = nullptr; activePosition = nullptr; idx = Threads.size(); // Starts from 0 @@ -115,7 +116,7 @@ bool Thread::available_to(const Thread* master) const { // Make a local copy to be sure it doesn't become zero under our feet while // testing next condition and so leading to an out of bounds access. - const int size = splitPointsSize; + const size_t size = splitPointsSize; // No split points means that the thread is available as a slave for any // other thread otherwise apply the "helpful master" concept if possible. @@ -144,7 +145,7 @@ void Thread::split(Position& pos, Stack* ss, Value alpha, Value beta, Value* bes // Pick and init the next available split point SplitPoint& sp = splitPoints[splitPointsSize]; - sp.masterThread = this; + sp.master = this; sp.parentSplitPoint = activeSplitPoint; sp.slavesMask = 0, sp.slavesMask.set(idx); sp.depth = depth; @@ -164,8 +165,8 @@ void Thread::split(Position& pos, Stack* ss, Value alpha, Value beta, Value* bes // Try to allocate available threads and ask them to start searching setting // 'searching' flag. This must be done under lock protection to avoid concurrent // allocation of the same slave by another master. - Threads.mutex.lock(); - sp.mutex.lock(); + Threads.spinlock.acquire(); + sp.spinlock.acquire(); sp.allSlavesSearching = true; // Must be set under lock protection ++splitPointsSize; @@ -174,7 +175,8 @@ void Thread::split(Position& pos, Stack* ss, Value alpha, Value beta, Value* bes Thread* slave; - while ((slave = Threads.available_slave(this)) != nullptr) + while ( sp.slavesMask.count() < MAX_SLAVES_PER_SPLITPOINT + && (slave = Threads.available_slave(this)) != nullptr) { sp.slavesMask.set(slave->idx); slave->activeSplitPoint = &sp; @@ -186,8 +188,8 @@ void Thread::split(Position& pos, Stack* ss, Value alpha, Value beta, Value* bes // it will instantly launch a search, because its 'searching' flag is set. // The thread will return from the idle loop when all slaves have finished // their work at this split point. - sp.mutex.unlock(); - Threads.mutex.unlock(); + sp.spinlock.release(); + Threads.spinlock.release(); Thread::idle_loop(); // Force a call to base class idle_loop() @@ -200,8 +202,8 @@ void Thread::split(Position& pos, Stack* ss, Value alpha, Value beta, Value* bes // We have returned from the idle loop, which means that all threads are // finished. Note that setting 'searching' and decreasing splitPointsSize must // be done under lock protection to avoid a race with Thread::available_to(). - Threads.mutex.lock(); - sp.mutex.lock(); + Threads.spinlock.acquire(); + sp.spinlock.acquire(); searching = true; --splitPointsSize; @@ -211,8 +213,8 @@ void Thread::split(Position& pos, Stack* ss, Value alpha, Value beta, Value* bes *bestMove = sp.bestMove; *bestValue = sp.bestValue; - sp.mutex.unlock(); - Threads.mutex.unlock(); + sp.spinlock.release(); + Threads.spinlock.release(); }