-const int MAX_THREADS = 32;
-const int MAX_ACTIVE_SPLIT_POINTS = 8;
-
-struct SplitPoint {
-
- // Const data after splitPoint has been setup
- SplitPoint* parent;
- const Position* pos;
- Depth depth;
- Value beta;
- int nodeType;
- int ply;
- int master;
- Move threatMove;
-
- // Const pointers to shared data
- MovePicker* mp;
- SearchStack* ss;
-
- // Shared data
- Lock lock;
- volatile int64_t nodes;
- volatile Value alpha;
- volatile Value bestValue;
- volatile int moveCount;
- volatile bool is_betaCutoff;
- volatile bool is_slave[MAX_THREADS];
+
+/// ThreadBase struct is the base of the hierarchy from where we derive all the
+/// specialized thread classes.
+
+struct ThreadBase : public std::thread {
+
+ ThreadBase() { exit = false; }
+ virtual ~ThreadBase() = default;
+ virtual void idle_loop() = 0;
+ void notify_one();
+ void wait(std::atomic_bool& b);
+ void wait_while(std::atomic_bool& b);
+
+ Mutex mutex;
+ ConditionVariable sleepCondition;
+ std::atomic_bool exit;
+};
+
+
+/// Thread struct keeps together all the thread related stuff like locks, state,
+/// history and countermoves tables. 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, callsCnt;
+ std::atomic_bool searching, resetCallsCnt;
+
+ Position rootPos;
+ Search::RootMoveVector rootMoves;
+ Depth rootDepth;
+ HistoryStats history;
+ MovesStats counterMoves;
+ Depth completedDepth;