diff --git a/src/main.cpp b/src/main.cpp index ad68ca35..e4ebcc30 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,8 +37,8 @@ int main(int argc, char* argv[]) { Zobrist::init(); Bitbases::init_kpk(); Search::init(); - Threads.init(); Eval::init(); + Threads.init(); TT.set_size(Options["Hash"]); std::string args; @@ -47,4 +47,6 @@ int main(int argc, char* argv[]) { args += std::string(argv[i]) + " "; UCI::loop(args); + + Threads.exit(); } diff --git a/src/thread.cpp b/src/thread.cpp index 541610a1..50412468 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -196,9 +196,9 @@ void ThreadPool::init() { } -// d'tor cleanly terminates the threads when the program exits. +// exit() cleanly terminates the threads before the program exits. -ThreadPool::~ThreadPool() { +void ThreadPool::exit() { for (size_t i = 0; i < threads.size(); i++) delete threads[i]; diff --git a/src/thread.h b/src/thread.h index 6a929a98..38a29e8d 100644 --- a/src/thread.h +++ b/src/thread.h @@ -130,8 +130,8 @@ public: class ThreadPool { public: - void init(); // No c'tor, Threads object is global and engine shall be fully initialized - ~ThreadPool(); + void init(); // No c'tor and d'tor, threads rely on globals that should + void exit(); // be initialized and valid during the whole thread lifetime. Thread& operator[](size_t id) { return *threads[id]; } bool use_sleeping_threads() const { return useSleepingThreads; }