# HG changeset patch # User Sebastien Jodogne # Date 1778514141 -7200 # Node ID 6ebd2030e5a84d3ab3065baeed72e2f31fd8ffcf # Parent c5173fb5f2d274c49d72908325c612224ef33c2e improved efficiency of restarting thread pool diff -r c5173fb5f2d2 -r 6ebd2030e5a8 OrthancFramework/Sources/MultiThreading/ThreadPool.cpp --- a/OrthancFramework/Sources/MultiThreading/ThreadPool.cpp Mon May 11 14:26:01 2026 +0200 +++ b/OrthancFramework/Sources/MultiThreading/ThreadPool.cpp Mon May 11 17:42:21 2026 +0200 @@ -133,7 +133,9 @@ } } - workers_.join_all(); + assert(workers_.get() != NULL); + workers_->join_all(); + workers_.reset(NULL); // Cancel all the remaining tasks in the queue for (;;) @@ -270,9 +272,12 @@ state_ = State_Running; + assert(workers_.get() == NULL); + workers_.reset(new boost::thread_group); + for (unsigned int i = 0; i < countThreads_; i++) { - workers_.create_thread(boost::bind(&ThreadPool::WorkerLoop, this)); + workers_->create_thread(boost::bind(&ThreadPool::WorkerLoop, this)); } } else diff -r c5173fb5f2d2 -r 6ebd2030e5a8 OrthancFramework/Sources/MultiThreading/ThreadPool.h --- a/OrthancFramework/Sources/MultiThreading/ThreadPool.h Mon May 11 14:26:01 2026 +0200 +++ b/OrthancFramework/Sources/MultiThreading/ThreadPool.h Mon May 11 17:42:21 2026 +0200 @@ -44,12 +44,12 @@ class Task; - SharedMessageQueue queue_; - boost::thread_group workers_; - boost::mutex mutex_; - unsigned int countThreads_; - State state_; - unsigned int dequeueTimeoutMilliseconds_; + SharedMessageQueue queue_; + std::unique_ptr workers_; + boost::mutex mutex_; + unsigned int countThreads_; + State state_; + unsigned int dequeueTimeoutMilliseconds_; void StopInternal(bool throws);