Commit ac6b1e28 authored by Yang Zhang's avatar Yang Zhang Committed by Facebook Github Bot

Add ThreadPoolExecutor::numActiveThreads()

Summary: ThreadPoolExecutor could dynamically adjust number of threads according to workload. Add numActiveThreads() so we can check how many active threads are actually there, while numThreads() returns the upper bound of threads.

Reviewed By: djwatson

Differential Revision: D8683795

fbshipit-source-id: 09f3b4ee8570e2f2f9f97e939061693f3e0639af
parent bc809fb4
...@@ -117,6 +117,10 @@ size_t ThreadPoolExecutor::numThreads() { ...@@ -117,6 +117,10 @@ size_t ThreadPoolExecutor::numThreads() {
return maxThreads_.load(std::memory_order_relaxed); return maxThreads_.load(std::memory_order_relaxed);
} }
size_t ThreadPoolExecutor::numActiveThreads() {
return activeThreads_.load(std::memory_order_relaxed);
}
// Set the maximum number of running threads. // Set the maximum number of running threads.
void ThreadPoolExecutor::setNumThreads(size_t numThreads) { void ThreadPoolExecutor::setNumThreads(size_t numThreads) {
/* Since ThreadPoolExecutor may be dynamically adjusting the number of /* Since ThreadPoolExecutor may be dynamically adjusting the number of
......
...@@ -77,6 +77,11 @@ class ThreadPoolExecutor : public DefaultKeepAliveExecutor { ...@@ -77,6 +77,11 @@ class ThreadPoolExecutor : public DefaultKeepAliveExecutor {
size_t numThreads(); size_t numThreads();
void setNumThreads(size_t numThreads); void setNumThreads(size_t numThreads);
// Return actual number of active threads -- this could be different from
// numThreads() due to ThreadPoolExecutor's dynamic behavior.
size_t numActiveThreads();
/* /*
* stop() is best effort - there is no guarantee that unexecuted tasks won't * stop() is best effort - there is no guarantee that unexecuted tasks won't
* be executed before it returns. Specifically, IOThreadPoolExecutor's stop() * be executed before it returns. Specifically, IOThreadPoolExecutor's stop()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment