X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fthread.h;h=abb7a22333800f4aa2d648290640f71261e749ab;hp=459b1ddde9fe11daadd308bb5f717abfcc86dbd8;hb=00d9e9fd283b31e63389af091b158dbc3fedfc0e;hpb=3428a2875197c805c25fdd954ba3a24d00845a2a diff --git a/src/thread.h b/src/thread.h index 459b1ddd..abb7a223 100644 --- a/src/thread.h +++ b/src/thread.h @@ -44,15 +44,16 @@ const size_t MAX_THREADS = 128; struct ThreadBase : public std::thread { + ThreadBase() { exit = false; } virtual ~ThreadBase() = default; virtual void idle_loop() = 0; void notify_one(); - void wait(volatile const bool& b); - void wait_while(volatile const bool& b); + void wait(std::atomic& b); + void wait_while(std::atomic& b); Mutex mutex; ConditionVariable sleepCondition; - volatile bool exit = false; + std::atomic exit; }; @@ -72,7 +73,7 @@ struct Thread : public ThreadBase { Endgames endgames; size_t idx, PVIdx; int maxPly; - volatile bool searching; + std::atomic searching; Position rootPos; Search::RootMoveVector rootMoves; @@ -87,10 +88,11 @@ struct Thread : public ThreadBase { /// special threads: the main one and the recurring timer. struct MainThread : public Thread { + MainThread() { thinking = true; } // Avoid a race with start_thinking() virtual void idle_loop(); void join(); void think(); - volatile bool thinking = true; // Avoid a race with start_thinking() + std::atomic thinking; }; struct TimerThread : public ThreadBase {