mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-20 17:16:33 +08:00
Rewrite how threads are spawned
Instead of creating a running std::thread and returning, wait in Thread c'tor that the native thread of execution goes to sleep in idle_loop(). In this way we can simplify how search is started, because when main thread is idle we are sure also all other threads will be idle, in any case, even at thread creation and startup. After lazy smp went in, we can simpify and rewrite a lot of logic that is now no more needed. This is hopefully the final big cleanup. Tested for no regression at 5+0.1 with 3 threads: LLR: 2.95 (-2.94,2.94) [-5.00,0.00] Total: 17411 W: 3248 L: 3198 D: 10965 No functional change.
This commit is contained in:
@@ -290,12 +290,11 @@ void MainThread::search() {
|
||||
{
|
||||
th->maxPly = 0;
|
||||
th->rootDepth = DEPTH_ZERO;
|
||||
th->searching = true;
|
||||
if (th != this)
|
||||
{
|
||||
th->rootPos = Position(rootPos, th);
|
||||
th->rootMoves = rootMoves;
|
||||
th->notify_one(); // Wake up the thread and start searching
|
||||
th->start_searching();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,7 +323,7 @@ void MainThread::search() {
|
||||
// Wait until all threads have finished
|
||||
for (Thread* th : Threads)
|
||||
if (th != this)
|
||||
th->join();
|
||||
th->wait_for_search_finished();
|
||||
|
||||
// Check if there are threads with a better score than main thread.
|
||||
Thread* bestThread = this;
|
||||
|
||||
Reference in New Issue
Block a user