[#BloombergLP-bdlmt-MultipriorityThreadPool]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdlmt.adoc[bdlmt]::MultipriorityThreadPool
:relfileprefix: ../../
:mrdocs:

This class implements a thread&hyphen;enabled, integrally&hyphen;prioritized thread&hyphen;pool mechanism used for concurrently executing multiple user&hyphen;defined &quot;jobs&quot; supplied as either conventional C&hyphen;style functions taking an optional `void &ast;` data argument, or as more flexible functor objects&period;

== Synopsis

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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
class MultipriorityThreadPool;
----

== Type Aliases

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bdlmt/MultipriorityThreadPool/ThreadFunctor.adoc[`ThreadFunctor`] 
| `ThreadFunctor` is an alias for a function object that is invokable (with no arguments) and returns `void`&semi; its use is similar to that of a C&hyphen;style function pointer and optional `void &ast;` data pointer passed as arguments when creating a thread&period;
|===


== Enums

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bdlmt/MultipriorityThreadPool/_04enum.adoc[`Unnamed enum`] 
| Maximum number of distinct job priorities supported by this pool&period;
|===


== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bdlmt/MultipriorityThreadPool/2constructor-0a.adoc[`MultipriorityThreadPool`]         [.small]#[constructor]#
| Create a multi&hyphen;priority thread pool capable of concurrently executing the specified `numThreads` &quot;jobs&quot; with associated integer priorities in the specified range `&lsqb;0 &period;&period; numPriorities &hyphen; 1&rsqb;`, 0 being the most urgent&period; Optionally specify `threadAttributes` used to customize each worker thread created by this thread pool, in which case the attribute pertaining to whether the worker threads are created in the detached state is ignored&period; Optionally specify a `basicAllocator` used to supply memory&period; If `basicAllocator` is 0, the currently installed default allocator is used&period; The newly created thread pool will initially be enabled for enqueuing jobs, but with no worker threads created&period; The behavior is undefined unless `1 &lt;&equals; numThreads` and `1 &lt;&equals; numPriorities &lt;&equals; k&lowbar;MAX&lowbar;NUM&lowbar;PRIORITIES`&period;
| xref:BloombergLP/bdlmt/MultipriorityThreadPool/2destructor.adoc[`&#126;MultipriorityThreadPool`] [.small]#[destructor]#
| Remove (cancel) all pending jobs and destroy this multi&hyphen;priority thread pool&period; The behavior is undefined unless this thread pool is stopped&period;
| xref:BloombergLP/bdlmt/MultipriorityThreadPool/disableQueue.adoc[`disableQueue`] 
| Disable the enqueuing of jobs to this multi&hyphen;priority thread pool&period; When this thread pool is disabled, the status returned when calling either overloaded `enqueueJob` method will be non&hyphen;zero, indicating that the job was _not_ enqueued&period; Note that calling this method when the queue is already in the disabled state has no effect&period;
| xref:BloombergLP/bdlmt/MultipriorityThreadPool/drainJobs.adoc[`drainJobs`] 
| Block until all executing jobs and pending jobs enqueued to this multi&hyphen;priority thread pool complete&period; This method does not affect the enabled&sol;disabled state of this thread pool&period; If this thread pool is enabled and jobs are enqueued during draining, this method may return before all enqueued jobs are executed&period; The behavior is undefined if&colon;
| xref:BloombergLP/bdlmt/MultipriorityThreadPool/enableQueue.adoc[`enableQueue`] 
| Enable the enqueuing of jobs to this multi&hyphen;priority thread pool&period; When this thread pool is enabled, the status returned when calling either overloaded `enqueueJob` method will be 0, indicating that the job was successfully enqueued&period; Note that calling this method when the queue is already in the enabled state has no effect&period;
| xref:BloombergLP/bdlmt/MultipriorityThreadPool/enqueueJob-0f.adoc[`enqueueJob`] 
| `enqueueJob` overloads
| xref:BloombergLP/bdlmt/MultipriorityThreadPool/isEnabled.adoc[`isEnabled`] 
| Return `true` if the enqueuing of new jobs is enabled for this multi&hyphen;priority thread pool, and `false` otherwise&period;
| xref:BloombergLP/bdlmt/MultipriorityThreadPool/isStarted.adoc[`isStarted`] 
| Return `true` if all `numThreads()` worker threads (specified at construction) have been created for this multi&hyphen;priority thread pool, and `false` otherwise&period;
| xref:BloombergLP/bdlmt/MultipriorityThreadPool/isSuspended.adoc[`isSuspended`] 
| Return `true` if the threads of this multi&hyphen;priority thread pool are currently suspended from processing jobs, and `false` otherwise&period;
| xref:BloombergLP/bdlmt/MultipriorityThreadPool/numActiveThreads.adoc[`numActiveThreads`] 
| Return a snapshot of the number of threads that are actively processing jobs for this multi&hyphen;priority thread pool&period; Note that `0 &lt;&equals; numActiveThreads() &lt;&equals; numThreads()` is an invariant of this class&period;
| xref:BloombergLP/bdlmt/MultipriorityThreadPool/numPendingJobs.adoc[`numPendingJobs`] 
| Return a snapshot of the number of jobs currently enqueued to be processed by this multi&hyphen;priority thread pool, but are not yet running&period;
| xref:BloombergLP/bdlmt/MultipriorityThreadPool/numPriorities.adoc[`numPriorities`] 
| Return the fixed number of priorities, specified at construction, that this multi&hyphen;priority thread pool supports&period;
| xref:BloombergLP/bdlmt/MultipriorityThreadPool/numStartedThreads.adoc[`numStartedThreads`] 
| Return the number of threads that have been started for this multi&hyphen;priority thread pool&period; Note that they may be currently suspended&period;
| xref:BloombergLP/bdlmt/MultipriorityThreadPool/numThreads.adoc[`numThreads`] 
| Returns the fixed number of threads, specified at construction, that are started by this multi&hyphen;priority thread pool&period;
| xref:BloombergLP/bdlmt/MultipriorityThreadPool/removeJobs.adoc[`removeJobs`] 
| Remove all pending (i&period;e&period;, not yet active) jobs from the queue of this multi&hyphen;priority thread pool&period; This method does not affect the enabled status of the queue, nor does it affect the started status or any active jobs in this thread pool&period; The behavior is undefined if this method is called concurrently with the `drainJobs` method&period; Note that, in this case, such undefined behavior may include deadlock&period;
| xref:BloombergLP/bdlmt/MultipriorityThreadPool/resumeProcessing.adoc[`resumeProcessing`] 
| If this multi&hyphen;priority thread pool is suspended, resume processing of jobs&period; This is orthogonal to start&sol;stop, and enable&sol;disable&semi; no threads are started&period; Note that this method has no effect if this thread pool is not in the suspended state&period;
| xref:BloombergLP/bdlmt/MultipriorityThreadPool/shutdown.adoc[`shutdown`] 
| Disable the enqueuing of new jobs to this multi&hyphen;priority thread pool, cancel all pending jobs, and stop all worker threads&period;
| xref:BloombergLP/bdlmt/MultipriorityThreadPool/startThreads.adoc[`startThreads`] 
| Create and start `numThreads()` worker threads in this multi&hyphen;priority thread pool&period; Return 0 on success, and a non&hyphen;zero value with no worker threads and no jobs processed otherwise&period; This method has no impact on the enabled&sol;disabled or suspended&sol;resumed states of this thread pool&period; Note that calling this method when this thread pool is already in the started state has no effect&period; Also note that until this method is called, the thread pool will not process any jobs&period;
| xref:BloombergLP/bdlmt/MultipriorityThreadPool/stopThreads.adoc[`stopThreads`] 
| Destroy all worker threads of this multi&hyphen;priority thread pool after waiting for any active (i&period;e&period;, already&hyphen;running) jobs to complete&semi; no new jobs will be allowed to become active&period; This method has no impact on the enabled&sol;disabled or suspended&sol;resumed states of this thread pool&period; Note that calling this function when this thread pool is not in the started state has no effect&period; Also note that calling this method from one of the threads belonging to this thread pool will cause a deadlock&period;
| xref:BloombergLP/bdlmt/MultipriorityThreadPool/suspendProcessing.adoc[`suspendProcessing`] 
| Put this multi&hyphen;priority thread pool into the suspended state&period; This method does not suspend any jobs that have begun to execute&semi; such jobs are allowed to complete&period; No pending jobs, however, will be allowed to begin execution until `resumeProcessing()` is called&period; This is orthogonal to start&sol;stop, and enable&sol;disable&semi; no threads are stopped&period; If this thread pool is started, this call blocks until all threads have finished any jobs they were processing and have gone into suspension&period; This method has no effect if this thread pool was already in the suspended state&period; Note that calling this method from one of the threads belonging to this thread pool will cause a deadlock&period;
| xref:BloombergLP/bdlmt/MultipriorityThreadPool/2conversion.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration&lt;MultipriorityThreadPool, UsesBslmaAllocator&gt;`] 
| Declare that this type uses a `bslma` allocator&period;
|===



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