mirror of
https://github.com/sockspls/badfish
synced 2025-07-11 19:49:14 +00:00
Small split() cleanup
Unify start loop for master and slave threads. Also guarantee that all the 'stop' flags are set to false before first slave is started, should be no harm because only master thread can reset 'stop' flag of slaves to true, so should be no race but better safe then sorry. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
81cfd81366
commit
dac1bcab90
1 changed files with 4 additions and 10 deletions
|
@ -2993,6 +2993,7 @@ namespace {
|
|||
splitPoint->slaves[i] = 0;
|
||||
|
||||
Threads[master].idle = false;
|
||||
Threads[master].stop = false;
|
||||
Threads[master].splitPoint = splitPoint;
|
||||
|
||||
// Allocate available threads setting idle flag to false
|
||||
|
@ -3000,6 +3001,7 @@ namespace {
|
|||
if (thread_is_available(i, master))
|
||||
{
|
||||
Threads[i].idle = false;
|
||||
Threads[i].stop = false;
|
||||
Threads[i].splitPoint = splitPoint;
|
||||
splitPoint->slaves[i] = 1;
|
||||
splitPoint->cpus++;
|
||||
|
@ -3010,22 +3012,14 @@ namespace {
|
|||
// We can release the lock because master and slave threads are already booked
|
||||
lock_release(&MPLock);
|
||||
|
||||
// Copy the tail of current search stack to the master thread
|
||||
memcpy(splitPoint->sstack[master] + ply - 1, sstck + ply - 1, 3 * sizeof(SearchStack));
|
||||
|
||||
// Tell the threads that they have work to do. This will make them leave
|
||||
// their idle loop. Also copy search stack tail for each slave thread.
|
||||
// their idle loop. But before copy search stack tail for each thread.
|
||||
for (int i = 0; i < ActiveThreads; i++)
|
||||
{
|
||||
if (splitPoint->slaves[i])
|
||||
memcpy(splitPoint->sstack[i] + ply - 1, sstck + ply - 1, 3 * sizeof(SearchStack));
|
||||
|
||||
if (i == master || splitPoint->slaves[i])
|
||||
{
|
||||
Threads[i].stop = false;
|
||||
memcpy(splitPoint->sstack[i] + ply - 1, sstck + ply - 1, 3 * sizeof(SearchStack));
|
||||
Threads[i].workIsWaiting = true; // This makes the slave to exit from idle_loop()
|
||||
}
|
||||
}
|
||||
|
||||
// Everything is set up. The master thread enters the idle loop, from
|
||||
// which it will instantly launch a search, because its workIsWaiting
|
||||
|
|
Loading…
Add table
Reference in a new issue