BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bdlmt::ThreadMultiplexor Class Reference

#include <bdlmt_threadmultiplexor.h>

Detailed Description

This class provides a mechanism for facilitating the use of multiple threads to perform various user-defined functions ("jobs") when some degree of collaboration between threads is required. The thread multiplexor is configured with a total number of "processors", representing the number of threads that may process jobs at any particular time. Additional threads enqueue jobs to a pending job queue, which is processed by the next available processing thread.

See bdlmt_threadmultiplexor

Public Types

typedef bsl::function< void()> Job
 

Public Member Functions

 BSLMF_NESTED_TRAIT_DECLARATION (ThreadMultiplexor, bslma::UsesBslmaAllocator)
 
 ThreadMultiplexor (int maxProcessors, int maxQueueSize, bslma::Allocator *basicAllocator=0)
 
 ~ThreadMultiplexor ()
 
template<class t_JOBTYPE >
int processJob (const t_JOBTYPE &job)
 
int maxProcessors () const
 
int numProcessors () const
 

Member Typedef Documentation

◆ Job

A callback of this type may be passed to the processJob method.

Constructor & Destructor Documentation

◆ ThreadMultiplexor()

bdlmt::ThreadMultiplexor::ThreadMultiplexor ( int  maxProcessors,
int  maxQueueSize,
bslma::Allocator basicAllocator = 0 
)

Create a thread multiplexor which uses, at most, the specified maxProcessors number of threads to process user-specified jobs, identified as callbacks of type Job. Jobs that cannot be processed immediately are placed on a queue having the specified maxQueueSize to be processed by the next free thread. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

Precondition
The behavior is undefined unless 0 < maxProcessors and 0 < maxQueueSize.

◆ ~ThreadMultiplexor()

bdlmt::ThreadMultiplexor::~ThreadMultiplexor ( )

Destroy this thread multiplexor object.

Member Function Documentation

◆ BSLMF_NESTED_TRAIT_DECLARATION()

bdlmt::ThreadMultiplexor::BSLMF_NESTED_TRAIT_DECLARATION ( ThreadMultiplexor  ,
bslma::UsesBslmaAllocator   
)

◆ maxProcessors()

int bdlmt::ThreadMultiplexor::maxProcessors ( ) const
inline

Return the maximum number of active processors.

◆ numProcessors()

int bdlmt::ThreadMultiplexor::numProcessors ( ) const
inline

Return the current number of active processors.

◆ processJob()

template<class t_JOBTYPE >
int bdlmt::ThreadMultiplexor::processJob ( const t_JOBTYPE &  job)
inline

Process the specified job functor in the calling thread if the current number of processors is less than the maximum number of processors. Otherwise, enqueue job to the pending job queue. Return 0 on success, and a non-zero value otherwise.

Note
Note that the only requirements on t_JOBTYPE are that it defines operator(), having a void return type, and that it defines a copy constructor.

The documentation for this class was generated from the following file: