-struct Thread {
- SplitPoint *splitPoint;
- int activeSplitPoints;
- uint64_t nodes;
- uint64_t betaCutOffs[2];
- bool failHighPly1;
- volatile bool stop;
- volatile bool running;
- volatile bool idle;
- volatile bool workIsWaiting;
- volatile bool printCurrentLine;
- unsigned char pad[64]; // set some distance among local data for each thread
+/// ThreadsManager class handles all the threads related stuff like init, starting,
+/// parking and, the most important, launching a slave thread at a split point.
+/// All the access to shared thread data is done through this class.
+
+class ThreadsManager {
+ /* As long as the single ThreadsManager object is defined as a global we don't
+ need to explicitly initialize to zero its data members because variables with
+ static storage duration are automatically set to zero before enter main()
+ */
+public:
+ void init();
+ void exit();
+
+ Thread& operator[](int id) { return *threads[id]; }
+ bool use_sleeping_threads() const { return useSleepingThreads; }
+ int min_split_depth() const { return minimumSplitDepth; }
+ int size() const { return (int)threads.size(); }
+
+ void wake_up();
+ void sleep();
+ void read_uci_options();
+ bool available_slave_exists(int master) const;
+ void set_timer(int msec);
+ void stop_thinking();
+ void start_thinking(const Position& pos, const Search::LimitsType& limits,
+ const std::set<Move>& = std::set<Move>(), bool async = false);
+
+ template <bool Fake>
+ Value split(Position& pos, Search::Stack* ss, Value alpha, Value beta, Value bestValue, Move* bestMove,
+ Depth depth, Move threatMove, int moveCount, MovePicker* mp, int nodeType);
+private:
+ friend class Thread;
+
+ std::vector<Thread*> threads;
+ Thread* timer;
+ Lock splitLock;
+ WaitCondition sleepCond;
+ Depth minimumSplitDepth;
+ int maxThreadsPerSplitPoint;
+ bool useSleepingThreads;