+// is_available_to() checks whether the thread is available to help the thread with
+// threadID "master" at a split point. An obvious requirement is that thread must be
+// idle. With more than two threads, this is not by itself sufficient: If the thread
+// is the master of some active split point, it is only available as a slave to the
+// threads which are busy searching the split point at the top of "slave"'s split
+// point stack (the "helpful master concept" in YBWC terminology).
+
+bool Thread::is_available_to(int master) const {
+
+ if (is_searching)
+ return false;
+
+ // Make a local copy to be sure doesn't become zero under our feet while
+ // testing next condition and so leading to an out of bound access.
+ int spCnt = splitPointsCnt;
+
+ // No active split points means that the thread is available as a slave for any
+ // other thread otherwise apply the "helpful master" concept if possible.
+ return !spCnt || (splitPoints[spCnt - 1].slavesMask & (1ULL << master));
+}
+
+
+// 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 ThreadsManager::read_uci_options() {
+
+ maxThreadsPerSplitPoint = Options["Max Threads per Split Point"];
+ minimumSplitDepth = Options["Min Split Depth"] * ONE_PLY;
+ useSleepingThreads = Options["Use Sleeping Threads"];
+ int requested = Options["Threads"];
+
+ while (size() < requested)
+ threads.push_back(new Thread(size()));
+
+ while (size() > requested)