mirror of
https://github.com/sockspls/badfish
synced 2025-07-11 19:49:14 +00:00
Simplify nosleep logic
Avoid redundant 'while' conditions. It is enough to check them in the outer loop. Quick tested for no regression 10K games at 4 threads ELO: -1.32 +-3.9 (95%) LOS: 25.6% Total: 10000 W: 1653 L: 1691 D: 6656 No functional change.
This commit is contained in:
parent
2e8552db76
commit
9a6cfee73b
2 changed files with 18 additions and 22 deletions
|
@ -278,10 +278,13 @@ void Search::think() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Thread* th : Threads)
|
for (Thread* th : Threads)
|
||||||
|
{
|
||||||
th->maxPly = 0;
|
th->maxPly = 0;
|
||||||
|
th->notify_one(); // Wake up all the threads
|
||||||
|
}
|
||||||
|
|
||||||
Threads.timer->run = true;
|
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 !
|
id_loop(RootPos); // Let's start searching !
|
||||||
|
|
||||||
|
@ -1591,25 +1594,8 @@ void Thread::idle_loop() {
|
||||||
|
|
||||||
assert(!this_sp || (this_sp->master == this && searching));
|
assert(!this_sp || (this_sp->master == this && searching));
|
||||||
|
|
||||||
while ( !exit
|
while (!exit && !(this_sp && this_sp->slavesMask.none()))
|
||||||
&& !(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<Mutex> 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
|
// If this thread has been assigned work, launch a search
|
||||||
while (searching)
|
while (searching)
|
||||||
{
|
{
|
||||||
|
@ -1715,6 +1701,18 @@ void Thread::idle_loop() {
|
||||||
sp->spinlock.release();
|
sp->spinlock.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If search is finished then sleep, otherwise just yield
|
||||||
|
if (!Threads.main()->thinking)
|
||||||
|
{
|
||||||
|
assert(!this_sp);
|
||||||
|
|
||||||
|
std::unique_lock<Mutex> 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -373,7 +373,5 @@ void ThreadPool::start_thinking(const Position& pos, const LimitsType& limits,
|
||||||
RootMoves.push_back(RootMove(m));
|
RootMoves.push_back(RootMove(m));
|
||||||
|
|
||||||
main()->thinking = true;
|
main()->thinking = true;
|
||||||
|
main()->notify_one(); // Wake up main thread: 'thinking' must be already set
|
||||||
for (Thread* th : *this)
|
|
||||||
th->notify_one();
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue