Quick Links:

bal | bbl | bdl | bsl

Public Member Functions

bslmt::ThreadGroup Class Reference

#include <bslmt_threadgroup.h>

List of all members.

Public Member Functions

 ThreadGroup (bslma::Allocator *basicAllocator=0)
 ~ThreadGroup ()
template<class INVOKABLE >
int addThread (const INVOKABLE &functor)
template<class INVOKABLE >
int addThread (const INVOKABLE &functor, const ThreadAttributes &attributes)
template<class INVOKABLE >
int addThreads (const INVOKABLE &functor, int numThreads)
template<class INVOKABLE >
int addThreads (const INVOKABLE &functor, int numThreads, const ThreadAttributes &attributes)
void joinAll ()
int numThreads () const

Detailed Description

This class provides a simple mechanism for managing a group of joinable threads. The destructor ensures that any running threads are detached so that resources are not leaked. This class is thread-enabled, thread-safe, and exception-neutral.

See Component bslmt_threadgroup


Constructor & Destructor Documentation

bslmt::ThreadGroup::ThreadGroup ( bslma::Allocator basicAllocator = 0  )  [explicit]

Create an empty thread group. Optionally specify basicAllocator will be used to supply memory. If basicAllocator is 0, the currently installed default allocator will be used.

bslmt::ThreadGroup::~ThreadGroup (  ) 

Destroy this object. Any threads not joined will be allowed to run independently, and will no longer be joinable.


Member Function Documentation

template<class INVOKABLE >
int bslmt::ThreadGroup::addThread ( const INVOKABLE &  functor  ) 
template<class INVOKABLE >
int bslmt::ThreadGroup::addThread ( const INVOKABLE &  functor,
const ThreadAttributes attributes 
)

Begin executing the specified invokable functor in a new thread, using the optionally specified thread attributes. Return 0 on success, and a non-zero value otherwise. INVOKABLE shall be a copy-constructible type having the equivalent of void operator()(). Note that threads are always created joinable, regardless of the mode specified in attributes.

template<class INVOKABLE >
int bslmt::ThreadGroup::addThreads ( const INVOKABLE &  functor,
int  numThreads 
)
template<class INVOKABLE >
int bslmt::ThreadGroup::addThreads ( const INVOKABLE &  functor,
int  numThreads,
const ThreadAttributes attributes 
)

Begin executing the specified invokable functor in the specified new numThreads, using the optionally specified thread attributes. Return numThreads on success, or the number of threads successfully started otherwise. INVOKABLE shall be a copy-constructible type having the equivalent of void operator()(). Note that threads are always created joinable, regardless of the mode specified in attributes.

void bslmt::ThreadGroup::joinAll (  ) 

Block the calling thread until all threads started in this group have finished executing.

int bslmt::ThreadGroup::numThreads (  )  const

Return a snapshot of the number of threads started in this group that have not been joined.


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