+
+/// ThreadBase struct is the base of the hierarchy from where we derive all the
+/// specialized thread classes.
+
+struct ThreadBase : public std::thread {
+
+ virtual ~ThreadBase() = default;
+ virtual void idle_loop() = 0;
+ void notify_one();
+ void wait(volatile const bool& b);
+ void wait_while(volatile const bool& b);
+
+ Mutex mutex;
+ ConditionVariable sleepCondition;
+ volatile bool exit = false;
+};
+
+
+/// Thread struct keeps together all the thread related stuff like locks, state
+/// and especially split points. We also use per-thread pawn and material hash
+/// tables so that once we get a pointer to an entry its life time is unlimited
+/// and we don't have to care about someone changing the entry under our feet.
+
+struct Thread : public ThreadBase {
+
+ Thread();
+ virtual void idle_loop();
+ void search(bool isMainThread = false);
+
+ Pawns::Table pawnsTable;
+ Material::Table materialTable;
+ Endgames endgames;
+ size_t idx, PVIdx;
+ int maxPly;
+ volatile bool searching;
+
+ Position rootPos;
+ Search::RootMoveVector rootMoves;
+ Search::Stack stack[MAX_PLY+4];
+ HistoryStats History;
+ MovesStats Countermoves;