[#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&hyphen;defined functions (&quot;jobs&quot;)&period;

== Synopsis

Declared in `&lt;bdlmt&lowbar;threadpool&period;h&gt;`

[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[`&#126;ThreadPool`] [.small]#[destructor]#
| Call `shutdown()` and destroy this thread pool&period;
| xref:BloombergLP/bdlmt/ThreadPool/drain.adoc[`drain`] 
| Disable queuing on this thread pool and wait until all pending jobs complete&period; Use `start` to re&hyphen;enable queuing&period;
| xref:BloombergLP/bdlmt/ThreadPool/enabled.adoc[`enabled`] 
| Return the state (enabled or not) of the thread pool&period;
| 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&period;
| 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&period;
| xref:BloombergLP/bdlmt/ThreadPool/maxThreads.adoc[`maxThreads`] 
| Return the maximum number of threads that are allowed to be running at given time&period;
| xref:BloombergLP/bdlmt/ThreadPool/minThreads.adoc[`minThreads`] 
| Return the minimum number of threads that must be started at any given time&period;
| xref:BloombergLP/bdlmt/ThreadPool/numActiveThreads.adoc[`numActiveThreads`] 
| Return the number of threads that are currently processing a job&period;
| xref:BloombergLP/bdlmt/ThreadPool/numPendingJobs.adoc[`numPendingJobs`] 
| Return the number of jobs that are currently queued, but not yet being processed&period;
| xref:BloombergLP/bdlmt/ThreadPool/numWaitingThreads.adoc[`numWaitingThreads`] 
| Return the number of threads that are currently waiting for a job&period;
| 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&period; The creation of the thread pool is considered a first reset time&period; This value is calculated as&colon; &grave; sum(jobExecutionTime) 100% P&lowbar;busy &equals; &hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen; x &hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen; timeSinceLastReset maxThreads &grave; Note that this percentage reflects the wall time spent per thread, and not CPU time per thread, or not even CPU time per processor&period; Also note that there is no guarantee that all threads are processed concurrently (e&period;g&period;, the number of threads could be larger than the number of processors)&period;
| 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&period; The creation of the thread pool is considered a first reset time&period; This value is calculated as&colon; &grave; sum(jobExecutionTime) 100% P&lowbar;busy &equals; &hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen; x &hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen;&hyphen; timeSinceLastReset maxThreads &grave; Note that this percentage reflects the wall time spent per thread, and not CPU time per thread, or not even CPU time per processor&period; Also note that there is no guarantee that all threads are processed concurrently (e&period;g&period;, the number of threads could be larger than the number of processors)&period;
| 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)&period;
| xref:BloombergLP/bdlmt/ThreadPool/start.adoc[`start`] 
| Enable queuing on this thread pool and spawn `minThreads()` processing threads&period; Return 0 on success, and a non&hyphen;zero value otherwise&period; If `minThreads()` threads were not successfully started, all threads are stopped&period;
| 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&period;
| xref:BloombergLP/bdlmt/ThreadPool/threadFailures.adoc[`threadFailures`] 
| Return the number of times that thread creation failed&period;
| xref:BloombergLP/bdlmt/ThreadPool/2conversion.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration&lt;ThreadPool, UsesBslmaAllocator&gt;`] 
| Declare that this type uses a `bslma` allocator&period;
|===


== Friends

[cols="1,4"]
|===
| Name| Description
| `xref:BloombergLP/bdlmt/ThreadPoolEntry.adoc[BloombergLP::bdlmt::ThreadPoolEntry]`
| Entry point for processing threads&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
