// ThreadBase::wait() set the thread to sleep until 'condition' turns true
-void ThreadBase::wait(std::atomic<bool>& condition) {
+void ThreadBase::wait(std::atomic_bool& condition) {
std::unique_lock<Mutex> lk(mutex);
sleepCondition.wait(lk, [&]{ return bool(condition); });
// ThreadBase::wait_while() set the thread to sleep until 'condition' turns false
-void ThreadBase::wait_while(std::atomic<bool>& condition) {
+void ThreadBase::wait_while(std::atomic_bool& condition) {
std::unique_lock<Mutex> lk(mutex);
sleepCondition.wait(lk, [&]{ return !condition; });
Thread::Thread() {
- searching = false;
- maxPly = 0;
+ searching = resetCallsCnt = false;
+ maxPly = callsCnt = 0;
history.clear();
counterMoves.clear();
idx = Threads.size(); // Starts from 0
}
-// TimerThread::idle_loop() is where the timer thread waits Resolution milliseconds
-// and then calls check_time(). When not searching, thread sleeps until it's woken up.
-
-void TimerThread::idle_loop() {
-
- while (!exit)
- {
- std::unique_lock<Mutex> lk(mutex);
-
- if (!exit)
- sleepCondition.wait_for(lk, std::chrono::milliseconds(run ? Resolution : INT_MAX));
-
- lk.unlock();
-
- if (!exit && run)
- check_time();
- }
-}
-
-
// Thread::idle_loop() is where the thread is parked when it has no work to do
void Thread::idle_loop() {
void ThreadPool::init() {
- timer = new_thread<TimerThread>();
push_back(new_thread<MainThread>());
read_uci_options();
}
void ThreadPool::exit() {
- delete_thread(timer); // As first because check_time() accesses threads data
- timer = nullptr;
-
for (Thread* th : *this)
delete_thread(th);