mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-20 00:56:39 +08:00
Do not call exit_threads() in Application d'tor
Because exit_threads() references the global object TM, we need to call the function when still inside main(), otherwise, due to undefined global object initialization and destruction we could end up with referencing an already destroyed object. Actually this should not happen because Application singleton is initialized _only_ after all the other globals due to how Application::initialize() is defined, but this is very tricky C++ and not easy to follow, even for me ;-) Also rearranged a bit main() code flow. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
@@ -57,12 +57,6 @@ Application::Application() {
|
||||
genrand_int32();
|
||||
}
|
||||
|
||||
Application::~Application() {
|
||||
|
||||
exit_threads();
|
||||
quit_eval();
|
||||
}
|
||||
|
||||
void Application::initialize() {
|
||||
|
||||
// A static Application object is allocated
|
||||
@@ -70,7 +64,15 @@ void Application::initialize() {
|
||||
static Application singleton;
|
||||
}
|
||||
|
||||
void Application::free_resources() {
|
||||
|
||||
// Warning, following functions reference global objects that
|
||||
// must be still alive when free_resources() is called.
|
||||
exit_threads();
|
||||
quit_eval();
|
||||
}
|
||||
|
||||
void Application::exit_with_failure() {
|
||||
|
||||
exit(EXIT_FAILURE); // d'tor will be called automatically
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user