[#BloombergLP-bdlmt-ThreadPool] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdlmt.adoc[bdlmt]::ThreadPool :relfileprefix: ../../ :mrdocs: This class implements a thread pool used for concurrently executing multiple user‐defined functions ("jobs"). == Synopsis Declared in `<bdlmt_threadpool.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- class ThreadPool; ---- == Type Aliases [cols="1"] |=== | Name | xref:BloombergLP/bdlmt/ThreadPool/Job.adoc[`Job`] |=== == Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bdlmt/ThreadPool/2constructor-0e.adoc[`ThreadPool`] [.small]#[constructor]# | Constructors | xref:BloombergLP/bdlmt/ThreadPool/2destructor.adoc[`~ThreadPool`] [.small]#[destructor]# | Call `shutdown()` and destroy this thread pool. | xref:BloombergLP/bdlmt/ThreadPool/drain.adoc[`drain`] | Disable queuing on this thread pool and wait until all pending jobs complete. Use `start` to re‐enable queuing. | xref:BloombergLP/bdlmt/ThreadPool/enabled.adoc[`enabled`] | Return the state (enabled or not) of the thread pool. | xref:BloombergLP/bdlmt/ThreadPool/enqueueJob-0e.adoc[`enqueueJob`] | `enqueueJob` overloads | xref:BloombergLP/bdlmt/ThreadPool/maxIdleTime.adoc[`maxIdleTime`] | Return the amount of time (in milliseconds) a thread remains idle before being shut down when there are more than min threads started. | xref:BloombergLP/bdlmt/ThreadPool/maxIdleTimeInterval.adoc[`maxIdleTimeInterval`] | Return the amount of time a thread remains idle before being shut down when there are more than min threads started. | xref:BloombergLP/bdlmt/ThreadPool/maxThreads.adoc[`maxThreads`] | Return the maximum number of threads that are allowed to be running at given time. | xref:BloombergLP/bdlmt/ThreadPool/minThreads.adoc[`minThreads`] | Return the minimum number of threads that must be started at any given time. | xref:BloombergLP/bdlmt/ThreadPool/numActiveThreads.adoc[`numActiveThreads`] | Return the number of threads that are currently processing a job. | xref:BloombergLP/bdlmt/ThreadPool/numPendingJobs.adoc[`numPendingJobs`] | Return the number of jobs that are currently queued, but not yet being processed. | xref:BloombergLP/bdlmt/ThreadPool/numWaitingThreads.adoc[`numWaitingThreads`] | Return the number of threads that are currently waiting for a job. | xref:BloombergLP/bdlmt/ThreadPool/percentBusy.adoc[`percentBusy`] | Return the percentage of wall time spent by each thread of this thread pool executing jobs since the last reset time. The creation of the thread pool is considered a first reset time. This value is calculated as: ` sum(jobExecutionTime) 100% P_busy = ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ x ‐‐‐‐‐‐‐‐‐‐ timeSinceLastReset maxThreads ` Note that this percentage reflects the wall time spent per thread, and not CPU time per thread, or not even CPU time per processor. Also note that there is no guarantee that all threads are processed concurrently (e.g., the number of threads could be larger than the number of processors). | xref:BloombergLP/bdlmt/ThreadPool/resetPercentBusy.adoc[`resetPercentBusy`] | Atomically report the percentage of wall time spent by each thread of this thread pool executing jobs since the last reset time, and set the reset time to now. The creation of the thread pool is considered a first reset time. This value is calculated as: ` sum(jobExecutionTime) 100% P_busy = ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ x ‐‐‐‐‐‐‐‐‐‐ timeSinceLastReset maxThreads ` Note that this percentage reflects the wall time spent per thread, and not CPU time per thread, or not even CPU time per processor. Also note that there is no guarantee that all threads are processed concurrently (e.g., the number of threads could be larger than the number of processors). | xref:BloombergLP/bdlmt/ThreadPool/shutdown.adoc[`shutdown`] | Disable queuing on this thread pool, cancel all queued jobs, and shut down all processing threads (after all active jobs complete). | xref:BloombergLP/bdlmt/ThreadPool/start.adoc[`start`] | Enable queuing on this thread pool and spawn `minThreads()` processing threads. Return 0 on success, and a non‐zero value otherwise. If `minThreads()` threads were not successfully started, all threads are stopped. | xref:BloombergLP/bdlmt/ThreadPool/stop.adoc[`stop`] | Disable queuing on this thread pool and wait until all pending jobs complete, then shut down all processing threads. | xref:BloombergLP/bdlmt/ThreadPool/threadFailures.adoc[`threadFailures`] | Return the number of times that thread creation failed. | xref:BloombergLP/bdlmt/ThreadPool/2conversion.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration<ThreadPool, UsesBslmaAllocator>`] | Declare that this type uses a `bslma` allocator. |=== == Friends [cols="1,4"] |=== | Name| Description | `xref:BloombergLP/bdlmt/ThreadPoolEntry.adoc[BloombergLP::bdlmt::ThreadPoolEntry]` | Entry point for processing threads. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#