X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fthread.cpp;h=a644cae9b64ede6d5a1e682cd62f5aff9b4e01af;hp=7b9a4f327823a4e0e60bcf9492d972ea0ccaa16d;hb=f59323b56a0920676c2589a36356a44fc42c8f40;hpb=b1f57e92cea7bd36126ef8c26928d8991b74baef diff --git a/src/thread.cpp b/src/thread.cpp index 7b9a4f32..a644cae9 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -28,22 +28,17 @@ using namespace Search; ThreadsManager Threads; // Global object -THREAD_LOCAL Thread* this_thread; // Thread local variable namespace { extern "C" { // start_routine() is the C function which is called when a new thread // is launched. It is a wrapper to member function pointed by start_fn. - long start_routine(Thread* th) { - - this_thread = th; // Save pointer into thread local storage - (th->*(th->start_fn))(); - return 0; - } + long start_routine(Thread* th) { (th->*(th->start_fn))(); return 0; } } } + // Thread c'tor starts a newly-created thread of execution that will call // the idle loop function pointed by start_fn going immediately to sleep. @@ -210,7 +205,6 @@ void ThreadsManager::init() { lock_init(splitLock); timer = new Thread(&Thread::timer_loop); threads.push_back(new Thread(&Thread::main_loop)); - this_thread = main_thread(); // Use main thread's resources read_uci_options(); } @@ -313,18 +307,19 @@ Value ThreadsManager::split(Position& pos, Stack* ss, Value alpha, Value beta, assert(beta <= VALUE_INFINITE); assert(depth > DEPTH_ZERO); - Thread* master = this_thread; + Thread* master = pos.this_thread(); if (master->splitPointsCnt >= MAX_SPLITPOINTS_PER_THREAD) return bestValue; // Pick the next available split point from the split point stack - SplitPoint* sp = &master->splitPoints[master->splitPointsCnt++]; + SplitPoint* sp = &master->splitPoints[master->splitPointsCnt]; sp->parent = master->curSplitPoint; sp->master = master; sp->cutoff = false; sp->slavesMask = 1ULL << master->idx; + sp->allSlavesMask = 1ULL << master->idx; sp->depth = depth; sp->bestMove = *bestMove; sp->threatMove = threatMove; @@ -353,6 +348,7 @@ Value ThreadsManager::split(Position& pos, Stack* ss, Value alpha, Value beta, if (threads[i]->is_available_to(master)) { sp->slavesMask |= 1ULL << i; + sp->allSlavesMask |= 1ULL << i; threads[i]->curSplitPoint = sp; threads[i]->is_searching = true; // Slave leaves idle_loop() @@ -360,9 +356,14 @@ Value ThreadsManager::split(Position& pos, Stack* ss, Value alpha, Value beta, threads[i]->wake_up(); if (++slavesCnt + 1 >= maxThreadsPerSplitPoint) // Master is always included + { + sp->allSlavesMask = 0; // Disable reparenting to this split point break; + } } + master->splitPointsCnt++; + lock_release(splitLock); lock_release(sp->lock);