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

This class implements a dynamic, configurable pool of queues, each of which is processed serially by a thread pool&period;

== Synopsis

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

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

== Type Aliases

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bdlmt/MultiQueueThreadPool/CleanupFunctor.adoc[`CleanupFunctor`] 
| Defines a type alias for the queue cleanup functor type&period;
| xref:BloombergLP/bdlmt/MultiQueueThreadPool/Job.adoc[`Job`] 
| Defines a type alias for the job functor type&period;
| xref:BloombergLP/bdlmt/MultiQueueThreadPool/QueueRegistry.adoc[`QueueRegistry`] 
| Defines a type alias for the registry mapping queue IDs to queues&period;
|===


== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bdlmt/MultiQueueThreadPool/2constructor-01.adoc[`MultiQueueThreadPool`]         [.small]#[constructor]#
| Constructors
| xref:BloombergLP/bdlmt/MultiQueueThreadPool/2destructor.adoc[`&#126;MultiQueueThreadPool`] [.small]#[destructor]#
| Destroy this multi&hyphen;queue thread pool&period; Disable queuing on all queues, and wait until all queues are empty&period; Then, delete all queues, and shut down the thread pool if the thread pool is owned by this object&period; This method will block if any thread is executing `start` or `stop` at the time of the call&period;
| xref:BloombergLP/bdlmt/MultiQueueThreadPool/addJobAtFront-0b.adoc[`addJobAtFront`] 
| `addJobAtFront` overloads
| xref:BloombergLP/bdlmt/MultiQueueThreadPool/batchSize.adoc[`batchSize`] 
| Return an instantaneous snapshot of the execution batch size (see &lsqb;&rsqb;Execution Batch Size)) of the queue associated with the specified `id`, or &hyphen;1 if `id` is not a valid queue id&period; When a thread is selecting jobs for processing, if fewer than `batchSize` jobs are available then only the available jobs will be processed in the current batch&period;
| xref:BloombergLP/bdlmt/MultiQueueThreadPool/createQueue.adoc[`createQueue`] 
| Create a queue with unlimited capacity and a default number of initial elements&period; Return a non&hyphen;zero queue ID&period; The queue ID can be used to enqueue jobs to the queue, or to control or delete the queue&period;
| xref:BloombergLP/bdlmt/MultiQueueThreadPool/deleteQueue-04.adoc[`deleteQueue`] 
| `deleteQueue` overloads
| xref:BloombergLP/bdlmt/MultiQueueThreadPool/disableQueue.adoc[`disableQueue`] 
| Disable enqueuing to the queue associated with the specified `id`&period; Return 0 on success, and a non&hyphen;zero value otherwise&period; Note that this method differs from `pauseQueue` in that (1) `disableQueue` does _not_ stop processing for a queue, and (2) prevents additional jobs from being enqueued&period;
| xref:BloombergLP/bdlmt/MultiQueueThreadPool/drain.adoc[`drain`] 
| Wait until all queues are empty&period; This method waits until all non&hyphen;paused queues are empty without disabling the queues (and may thus wait indefinitely)&period; The queues and&sol;or the thread pool may be either enabled or disabled when this method is called&period; This method may be called on a stopped or started thread pool&period; Note that `drain` does not attempt to delete queues directly&period; However, as a side&hyphen;effect of emptying all queues, any queue for which `deleteQueue` was called previously will be deleted before `drain` returns&period; Note also that this method waits by repeatedly yielding&period;
| xref:BloombergLP/bdlmt/MultiQueueThreadPool/drainQueue.adoc[`drainQueue`] 
| Wait until all jobs in the queue indicated by the specified `id` are finished&period; This method simply waits until that queue is empty, without disabling the queue&semi; it may thus wait indefinitely if more jobs are being added&period; The queue may be enabled or disabled when this method is called&period; Return 0 on success, and a non&hyphen;zero value if the specified queue does not exist or is deleted while this method is waiting&period; Note that this method waits by repeatedly yielding&period;
| xref:BloombergLP/bdlmt/MultiQueueThreadPool/enableQueue.adoc[`enableQueue`] 
| Enable enqueuing to the queue associated with the specified `id`&period; Return 0 on success, and a non&hyphen;zero value otherwise&period; It is an error to call `enableQueue` if a previous call to `stop` is being executed&period;
| xref:BloombergLP/bdlmt/MultiQueueThreadPool/enqueueJob-0b.adoc[`enqueueJob`] 
| `enqueueJob` overloads
| xref:BloombergLP/bdlmt/MultiQueueThreadPool/isEnabled.adoc[`isEnabled`] 
| Return `true` if the queue associated with the specified `id` is currently enabled, or `false` otherwise (including if `id` is not a valid queue id)&period;
| xref:BloombergLP/bdlmt/MultiQueueThreadPool/isPaused.adoc[`isPaused`] 
| Return `true` if the queue associated with the specified `id` is currently paused, or `false` otherwise (including if `id` is not a valid queue id)&period;
| xref:BloombergLP/bdlmt/MultiQueueThreadPool/numElements-0f.adoc[`numElements`] 
| `numElements` overloads
| xref:BloombergLP/bdlmt/MultiQueueThreadPool/numProcessed.adoc[`numProcessed`] 
| Load into the specified `numExecuted` and `numEnqueued` the number of items dequeued &sol; enqueued (respectively) since the last time these values were reset&period; Optionally specify a `numDeleted` used to load into the number of items deleted since the last time this value was reset&period;
| xref:BloombergLP/bdlmt/MultiQueueThreadPool/numProcessedReset.adoc[`numProcessedReset`] 
| Load into the specified `numExecuted` and `numEnqueued` the number of items dequeued &sol; enqueued (respectively) since the last time these values were reset and reset these values&period; Optionally specify a `numDeleted` used to load into the number of items deleted since the last time this value was reset&period; Reset the count of deleted items&period;
| xref:BloombergLP/bdlmt/MultiQueueThreadPool/numQueues.adoc[`numQueues`] 
| Return an instantaneous snapshot of the number of queues managed by this object&period;
| xref:BloombergLP/bdlmt/MultiQueueThreadPool/pauseQueue.adoc[`pauseQueue`] 
| Wait until any currently&hyphen;executing job (or batch of jobs) on the queue with the specified `id` completes, then prevent any more jobs from being executed on that queue&period; Return 0 on success, and a non&hyphen;zero value if the queue is already paused or is being paused or deleted by another thread&period; Note that this method may be invoked from a job executing on the given queue, in which case this method does not wait&period; Note also that this method differs from `disableQueue` in that (1) `pauseQueue` stops processing for a queue, and (2) does _not_ prevent additional jobs from being enqueued&period;
| xref:BloombergLP/bdlmt/MultiQueueThreadPool/resumeQueue.adoc[`resumeQueue`] 
| Allow jobs on the queue with the specified `id` to begin executing&period; Return 0 on success, and a non&hyphen;zero value if the queue does not exist or is not paused&period;
| xref:BloombergLP/bdlmt/MultiQueueThreadPool/setBatchSize.adoc[`setBatchSize`] 
| Configure the queue specified by `id` to process jobs in groups of the specified `batchSize` (see &lcub;`Job Execution Batch Size`&rcub;)&period; When a thread is selecting jobs for processing, if fewer than `batchSize` jobs are available then only the available jobs will be processed in the current batch&period; Return 0 on success, and a non&hyphen;zero value otherwise&period; The behavior is undefined unless `1 &lt;&equals; batchSize`&period; Note that the initial value for the execution batch size is 1 for all queues&period;
| xref:BloombergLP/bdlmt/MultiQueueThreadPool/shutdown.adoc[`shutdown`] 
| Disable queuing on all queues, and wait until all non&hyphen;paused queues are empty&period; Then, delete all queues, and shut down the thread pool if the thread pool is owned by this object&period;
| xref:BloombergLP/bdlmt/MultiQueueThreadPool/start.adoc[`start`] 
| Enable queuing on all queues, start the thread pool if the thread pool is owned by this object, and ensure that at least the minimum number of processing threads are started&period; Return 0 on success, and a non&hyphen;zero value otherwise&period; This method will block if any thread is executing `stop` or `shutdown` at the time of the call&period; This method has no effect if this thread pool has already been started&period; Note that any paused queues remain paused&period;
| xref:BloombergLP/bdlmt/MultiQueueThreadPool/stop.adoc[`stop`] 
| Disable queuing on all queues and wait until all non&hyphen;paused queues are empty&period; Then, stop the thread pool if the thread pool is owned by this object&period; Note that `stop` does not attempt to delete queues directly&period; However, as a side&hyphen;effect of emptying all queues, any queue for which `deleteQueue` was called previously will be deleted before `stop` unblocks&period;
| xref:BloombergLP/bdlmt/MultiQueueThreadPool/threadPool.adoc[`threadPool`] 
| Return a reference to the non&hyphen;modifiable thread pool owned by this object&period;
| xref:BloombergLP/bdlmt/MultiQueueThreadPool/2conversion.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration&lt;MultiQueueThreadPool, UsesBslmaAllocator&gt;`] 
| Declare that this type uses a `bslma` allocator&period;
|===


== Friends

[cols="1,4"]
|===
| Name| Description
| `xref:BloombergLP/bdlmt/MultiQueueThreadPool_Queue.adoc[BloombergLP::bdlmt::MultiQueueThreadPool&lowbar;Queue]`
| This private class provides a thread&hyphen;safe, lightweight job queue&period;
|===


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