Quick Links: |
#include <bslmt_threadgroup.h>
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 |
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
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.
int bslmt::ThreadGroup::addThread | ( | const INVOKABLE & | functor | ) |
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
.
int bslmt::ThreadGroup::addThreads | ( | const INVOKABLE & | functor, | |
int | numThreads | |||
) |
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.