1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-07-11 19:49:14 +00:00

Fix a race in idle_loop() exiting

When pondering threads are put to sleep, but when thinking
the threads are parked in idle_loop in a tight polling loop
checking for workIsWaiting falg.

So before we set the slave's flag workIsWaiting we have to
guarantee that all the slave data is already setup because
slave can start in any moment from there.

Rearrange the last loop to fix this race.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2010-01-25 15:01:20 +01:00
parent c5858ff9ae
commit c5e71f5150

View file

@ -3010,13 +3010,14 @@ namespace {
// their idle loop. Also copy search stack tail for each slave thread. // their idle loop. Also copy search stack tail for each slave thread.
for (int i = 0; i < ActiveThreads; i++) for (int i = 0; i < ActiveThreads; i++)
{ {
if (i == master || splitPoint->slaves[i])
{
Threads[i].workIsWaiting = true;
Threads[i].stop = false;
}
if (splitPoint->slaves[i]) if (splitPoint->slaves[i])
memcpy(splitPoint->sstack[i] + ply - 1, sstck + ply - 1, 3 * sizeof(SearchStack)); memcpy(splitPoint->sstack[i] + ply - 1, sstck + ply - 1, 3 * sizeof(SearchStack));
if (i == master || splitPoint->slaves[i])
{
Threads[i].stop = false;
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 // Everything is set up. The master thread enters the idle loop, from