BDE 4.14.0 Production release
|
Provide a container for managing a group of threads.
This component provides a simple mechanism for managing a group of threads. The group is represented by an instance of the bslmt::ThreadGroup
class. To use this component, the client code calls addThread
, providing a function to be executed. The specified function is executed in a new thread managed by the thread group (note that addThread
is thread-safe). The joinAll
call blocks until all threads in the group have finished executing.
This component is thread-safe and thread-enabled, meaning that multiple threads may safely use their own instances or a shared instance of a bslmt::ThreadGroup
object.
This section illustrates intended use of this component.
The following usage example illustrates how bslmt::ThreadGroup
might be used in a typical test driver to simplify the execution of a common function in multiple threads. Suppose that we are interested in creating a stress-test for the bslmt::Mutex
class. The test is controlled by two parameters: the number of executions (defined by subsequent calls to lock
and unlock
, and the amount of contention, defined by the number of threads accessing the mutex. The test can be expressed as two functions. The first is executed in each thread via a functor object:
The second executes the main body of the test: