diff --git a/impl/ocean/base/ThreadPool.cpp b/impl/ocean/base/ThreadPool.cpp index 3663d8a4c..67bc6f1b1 100644 --- a/impl/ocean/base/ThreadPool.cpp +++ b/impl/ocean/base/ThreadPool.cpp @@ -175,7 +175,7 @@ void ThreadPool::threadRun() } } - while (capacity_ < busyPoolThreads_.size() + idlePoolThreads_.size() && idlePoolThreads_.empty()) + while (capacity_ < busyPoolThreads_.size() + idlePoolThreads_.size() && !idlePoolThreads_.empty()) { // we have an idle pool thread and we have more threads than the specified capacity (e.g., because the capacity has been reduced lately) diff --git a/impl/ocean/base/ThreadPool.h b/impl/ocean/base/ThreadPool.h index fb9e5307c..acab73eea 100644 --- a/impl/ocean/base/ThreadPool.h +++ b/impl/ocean/base/ThreadPool.h @@ -145,6 +145,12 @@ class OCEAN_BASE_EXPORT ThreadPool : protected Thread */ inline size_t pending() const; + /** + * Returns whether the ThreadPool has completed all jobs that have been submitted + * @return True, if the results of size() and pending() are atomically both 0 + */ + inline bool isEmpty() const; + protected: /** @@ -220,6 +226,13 @@ inline size_t ThreadPool::pending() const return pendingFunctions_.size(); } +inline bool ThreadPool::isEmpty() const +{ + const ScopedLock scopedLock(lock_); + + return (pendingFunctions_.size() + busyPoolThreads_.size()) == 0; +} + } #endif // META_OCEAN_BASE_THREAD_POOL_H