#include <algorithm>
#include <cassert>
+#include <cmath>
#include <cstdlib>
#include <deque>
#include <initializer_list>
ThreadPool Threads; // Global object
-// Thread constructor launches the thread and waits until it goes to sleep
+// Constructor launches the thread and waits until it goes to sleep
// in idle_loop(). Note that 'searching' and 'exit' should be already set.
-
Thread::Thread(size_t n) :
idx(n),
stdThread(&Thread::idle_loop, this) {
}
-// Thread destructor wakes up the thread in idle_loop() and waits
+// Destructor wakes up the thread in idle_loop() and waits
// for its termination. Thread should be already waiting.
-
Thread::~Thread() {
assert(!searching);
}
-// Thread::clear() reset histories, usually before a new game
-
+// Reset histories, usually before a new game
void Thread::clear() {
counterMoves.fill(MOVE_NONE);
mainHistory.fill(0);
captureHistory.fill(0);
+ pawnHistory.fill(0);
for (bool inCheck : {false, true})
for (StatsType c : {NoCaptures, Captures})
}
-// Thread::start_searching() wakes up the thread that will start the search
-
+// Wakes up the thread that will start the search
void Thread::start_searching() {
mutex.lock();
searching = true;
}
-// Thread::wait_for_search_finished() blocks on the condition variable
+// Blocks on the condition variable
// until the thread has finished searching.
-
void Thread::wait_for_search_finished() {
std::unique_lock<std::mutex> lk(mutex);
}
-// Thread::idle_loop() is where the thread is parked, blocked on the
+// Thread gets parked here, blocked on the
// condition variable, when it has no work to do.
void Thread::idle_loop() {
}
}
-// ThreadPool::set() creates/destroys threads to match the requested number.
+// Creates/destroys threads to match the requested number.
// Created and launched threads will immediately go to sleep in idle_loop.
// Upon resizing, threads are recreated to allow for binding if necessary.
-
void ThreadPool::set(size_t requested) {
if (threads.size() > 0) // destroy any existing thread(s)
}
-// ThreadPool::clear() sets threadPool data to initial values
-
+// Sets threadPool data to initial values
void ThreadPool::clear() {
for (Thread* th : threads)
}
-// ThreadPool::start_thinking() wakes up main thread waiting in idle_loop() and
+// Wakes up main thread waiting in idle_loop() and
// returns immediately. Main thread will wake up other threads and start the search.
-
void ThreadPool::start_thinking(Position& pos,
StateListPtr& states,
const Search::LimitsType& limits,
votes[th->rootMoves[0].pv[0]] += thread_value(th);
for (Thread* th : threads)
- if (abs(bestThread->rootMoves[0].score) >= VALUE_TB_WIN_IN_MAX_PLY)
+ if (std::abs(bestThread->rootMoves[0].score) >= VALUE_TB_WIN_IN_MAX_PLY)
{
// Make sure we pick the shortest mate / TB conversion or stave off mate the longest
if (th->rootMoves[0].score > bestThread->rootMoves[0].score)