-// init() is called at startup to create and launch requested threads, that will
-// go immediately to sleep due to 'sleepWhileIdle' set to true. We cannot use
-// a c'tor becuase Threads is a static object and we need a fully initialized
-// engine at this point due to allocation of Endgames in Thread c'tor.
-
-void ThreadPool::init() {
-
- sleepWhileIdle = true;
- timer = new TimerThread();
- threads.push_back(new MainThread());
- read_uci_options();
-}
-
-
-// exit() cleanly terminates the threads before the program exits
-
-void ThreadPool::exit() {
-
- delete timer; // As first because check_time() accesses threads data
-
- for (size_t i = 0; i < threads.size(); i++)
- delete threads[i];
-}
-
-
-// read_uci_options() updates internal threads parameters from the corresponding
-// UCI options and creates/destroys threads to match the requested number. Thread
-// objects are dynamically allocated to avoid creating in advance all possible
-// threads, with included pawns and material tables, if only few are used.
-
-void ThreadPool::read_uci_options() {
-
- maxThreadsPerSplitPoint = Options["Max Threads per Split Point"];
- minimumSplitDepth = Options["Min Split Depth"] * ONE_PLY;
- size_t requested = Options["Threads"];
-
- assert(requested > 0);
-
- while (threads.size() < requested)
- threads.push_back(new Thread());
-
- while (threads.size() > requested)
- {
- delete threads.back();
- threads.pop_back();
- }
-}
-
-
-// slave_available() tries to find an idle thread which is available as a slave
-// for the thread 'master'.
-
-bool ThreadPool::slave_available(Thread* master) const {
-
- for (size_t i = 0; i < threads.size(); i++)
- if (threads[i]->is_available_to(master))
- return true;
-
- return false;
-}
-
-
-// split() does the actual work of distributing the work at a node between