// 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) {
-
- Threads.set_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.
void ThreadsManager::init() {
- tls_init(tlsKey);
cond_init(sleepCond);
lock_init(splitLock);
timer = new Thread(&Thread::timer_loop);
delete timer;
lock_destroy(splitLock);
cond_destroy(sleepCond);
- tls_destroy(tlsKey);
}
assert(beta <= VALUE_INFINITE);
assert(depth > DEPTH_ZERO);
- Thread* master = Threads.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;
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()
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);