Wait for main thread to finish before to exit

Currently after a 'quit' command UI thread raises stop
signal, exits from uci_loop() and calls Threads.exit()
while the search threads are still active.

In Threads.exit() main thread is asked to terminate, but
if it is parked in idle_loop() it will exit and free its
resources (in particular the shared Movepicker object) while
sibling slaves are still active and this leads to a crash.

The fix is to let the UI thread always wait for main thread
to finish the search before to return from uci_loop().

Found by Valgrind when running with 8 threads.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba
2011-12-29 09:55:09 +01:00
parent 4a8c1b2470
commit 9cb187762a
3 changed files with 25 additions and 8 deletions

View File

@@ -68,10 +68,7 @@ void uci_loop() {
is >> skipws >> token;
if (token == "quit" || token == "stop")
{
Search::Signals.stop = true;
Threads[0].wake_up(); // In case is waiting for stop or ponderhit
}
Threads.stop_thinking();
else if (token == "ponderhit")
{
@@ -81,9 +78,7 @@ void uci_loop() {
Search::Limits.ponder = false;
if (Search::Signals.stopOnPonderhit)
Search::Signals.stop = true;
Threads[0].wake_up(); // In case is waiting for stop or ponderhit
Threads.stop_thinking();
}
else if (token == "go")