-const int MAX_THREADS = 32;
-const int MAX_SPLITPOINTS_PER_THREAD = 8;
-
-struct SplitPoint {
-
- // Const data after split point has been setup
- const Position* pos;
- const Search::Stack* ss;
- Depth depth;
- Value beta;
- int nodeType;
- int master;
- Move threatMove;
-
- // Const pointers to shared data
- MovePicker* mp;
- SplitPoint* parent;
-
- // Shared data
- Lock lock;
- volatile uint64_t slavesMask;
- volatile int64_t nodes;
- volatile Value alpha;
- volatile Value bestValue;
- volatile Move bestMove;
- volatile int moveCount;
- volatile bool cutoff;
+
+/// Thread class keeps together all the thread-related stuff. We 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.
+
+class Thread {
+
+ Mutex mutex;
+ ConditionVariable cv;
+ size_t idx;
+ bool exit = false, searching = true; // Set before starting std::thread
+ std::thread stdThread;
+
+public:
+ explicit Thread(size_t);
+ virtual ~Thread();
+ virtual void search();
+ void clear();
+ void idle_loop();
+ void start_searching();
+ void wait_for_search_finished();
+
+ Pawns::Table pawnsTable;
+ Material::Table materialTable;
+ Endgames endgames;
+ size_t pvIdx, pvLast;
+ int selDepth, nmpMinPly;
+ Color nmpColor;
+ std::atomic<uint64_t> nodes, tbHits;
+
+ Position rootPos;
+ Search::RootMoves rootMoves;
+ Depth rootDepth, completedDepth;
+ CounterMoveHistory counterMoves;
+ ButterflyHistory mainHistory;
+ CapturePieceToHistory captureHistory;
+ ContinuationHistory contHistory;
+ Score contempt;