cpp-pthread
(v1.7.3)
Simple C++ wrapper to pthread functions.
|
#include <thread.hpp>
Public Member Functions | |
thread_group (bool destructor_joins_first=false) noexcept | |
virtual | ~thread_group () |
void | add (abstract_thread *thread) |
void | start () |
void | join () |
unsigned long | size () |
const bool | destructor_joins_first () |
Group of abstract_threads pointers.
This helper class is in charge of handling group of threads as a whole. Method in this class apply to all threads in the group.
When destroyed, a thread_group deletes the thread that were registered/added to it.
int main(int argc, const char * argv[]) {
pthread::thread_group threads; // this instance will free any registered thread when it will get out of scope
for (auto x = 10 ; x > 0 ; x--){
threads.add( new worker("herbert")); // register threads, they will run when start() is called
}
threads.start(); // start running all threads
threads.join(); // wait for registered threads to join
} // scope end
Definition at line 294 of file thread.hpp.
|
explicitnoexcept |
Setup a thread container/list.
destructor_joins_first | if true then destructor tries to wait for all registered threads to join the calling one before deleting thread instances. |
Definition at line 158 of file thread.cpp.
|
virtual |
delete all abstract_thread referenced by the thread_group.
If destructor_joins_first is true then the method abstract_thread::join() is called before deleting the referenced abstract_thread.
Definition at line 163 of file thread.cpp.
void pthread::thread_group::add | ( | pthread::abstract_thread * | thread | ) |
thread | add/register a thread. |
Definition at line 187 of file thread.cpp.
|
inline |
Definition at line 337 of file thread.hpp.
void pthread::thread_group::join | ( | ) |
Wait for all registered threads to join the caller thread.
The method iterates the list of abstract_thread and calls the join method of each entry found.
Definition at line 198 of file thread.cpp.
unsigned long pthread::thread_group::size | ( | ) |
Definition at line 206 of file thread.cpp.
void pthread::thread_group::start | ( | ) |
Start running all registered threads.
Definition at line 192 of file thread.cpp.