From 494aeb199daaea34621546532392b1fe146cfb54 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Thu, 8 Oct 2015 10:11:16 +0200 Subject: [PATCH] Fix a crash on exit In Thread::idle_loop() we now access main thread data, namely Threads.main()->thinking So upon exit we have to ensure main thread is the last one to be deleted. It can be easily reproduced setting more then one thread and then quitting. This bug happens also in original lazy_smp but for some reason remains hidden. Although a crash, this should not compromise TCEC version because it occurs only upon exiting the engine. No functional change. --- src/thread.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/thread.cpp b/src/thread.cpp index 050e58c3..2b94cf7b 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -190,8 +190,10 @@ void ThreadPool::exit() { timer = nullptr; for (Thread* th : *this) - delete_thread(th); + if (th != Threads.main()) + delete_thread(th); + delete_thread(Threads.main()); // Must be the last one clear(); // Get rid of stale pointers }