+
+/// ThreadPool 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 ThreadPool {
+ /* As long as the single ThreadPool 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(); // No c'tor becuase Threads is global and we need engine initialized
+ ~ThreadPool();
+
+ 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(); }
+ Thread* main_thread() { return threads[0]; }
+
+ void wake_up() const;
+ void sleep() const;
+ void read_uci_options();
+ bool available_slave_exists(Thread* master) const;
+ void set_timer(int msec);
+ void wait_for_search_finished();
+ void start_searching(const Position& pos, const Search::LimitsType& limits,
+ const std::vector<Move>& searchMoves);
+
+ 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;