-private:
- friend struct ConditionVariable;
-
- Lock l;
-};
-
-struct ConditionVariable {
- ConditionVariable() { cond_init(c); }
- ~ConditionVariable() { cond_destroy(c); }
-
- void wait(Mutex& m) { cond_wait(c, m.l); }
- void wait_for(Mutex& m, int ms) { timed_wait(c, m.l, ms); }
- void notify_one() { cond_signal(c); }
-
-private:
- WaitCondition c;
-};
-
-struct Thread;
-
-struct SplitPoint {
-
- // Const data after split point has been setup
- const Position* pos;
- const Search::Stack* ss;
- Thread* masterThread;
- Depth depth;
- Value beta;
- int nodeType;
- bool cutNode;
-
- // Const pointers to shared data
- MovePicker* movePicker;
- SplitPoint* parentSplitPoint;
-
- // Shared data
- Mutex mutex;
- std::bitset<MAX_THREADS> slavesMask;
- volatile uint64_t nodes;
- volatile Value alpha;
- volatile Value bestValue;
- volatile Move bestMove;
- volatile int moveCount;
- volatile bool cutoff;
-};
-
-
-/// ThreadBase struct is the base of the hierarchy from where we derive all the
-/// specialized thread classes.
-
-struct ThreadBase {
-
- ThreadBase() : handle(NativeHandle()), exit(false) {}
- virtual ~ThreadBase() {}
- virtual void idle_loop() = 0;
- void notify_one();
- void wait_for(volatile const bool& b);
+ std::mutex mutex;
+ std::condition_variable cv;
+ size_t idx;
+ bool exit = false, searching = true; // Set before starting std::thread
+ NativeThread stdThread;
+
+public:
+ explicit Thread(size_t);
+ virtual ~Thread();
+ virtual void search();
+ void clear();
+ void idle_loop();
+ void start_searching();
+ void wait_for_search_finished();
+ size_t id() const { return idx; }