mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 16:53:09 +00:00
Fix race in ThreadsManager::sleep()
We cannot set do_sleep flag of main thread before "bestmove" is sent to GUI, otherwise GUI could send immediately the next "go" command that triggers start_thinking() and because do_sleep is set UI thread resets the flag to launch a new search. But when shortly after main thread returns to main_loop() flag is incorrectly reset and main thread goes to sleep hanging the engine. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
c483ffc773
commit
58c2fe391d
1 changed files with 5 additions and 4 deletions
|
@ -227,7 +227,7 @@ void ThreadsManager::read_uci_options() {
|
|||
|
||||
void ThreadsManager::wake_up() {
|
||||
|
||||
for (int i = 0; i < size(); i++)
|
||||
for (int i = 1; i < size(); i++) // Main thread is already running
|
||||
{
|
||||
threads[i]->do_sleep = false;
|
||||
|
||||
|
@ -237,12 +237,13 @@ void ThreadsManager::wake_up() {
|
|||
}
|
||||
|
||||
|
||||
// sleep() is called after the search to ask threads to wait on sleep condition
|
||||
// sleep() is called after the search to ask all the threads but the main to go
|
||||
// waiting on a sleep condition.
|
||||
|
||||
void ThreadsManager::sleep() {
|
||||
|
||||
for (int i = 0; i < size(); i++)
|
||||
threads[i]->do_sleep = true;
|
||||
for (int i = 1; i < size(); i++) // Main thread will go to sleep by itself
|
||||
threads[i]->do_sleep = true; // to avoid a race with start_thinking()
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue