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);
}
-// 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,