Loading...
Searching...
No Matches
threadgroup.h
Go to the documentation of this file.
#ifndef DYSCO_THREADGROUP_H
#define DYSCO_THREADGROUP_H
#include <stdexcept>
#include <thread>
#include <vector>
namespace dyscostman {
class threadgroup {
public:
threadgroup() {}
~threadgroup() { join_all(); }
template <typename T>
void create_thread(T threadFunc) {
_threads.emplace_back(threadFunc);
}
void join_all() {
for (std::thread &t : _threads) {
t.join();
}
_threads.clear();
}
bool empty() const { return _threads.empty(); }
private:
std::vector<std::thread> _threads;
};
} // namespace dyscostman
#endif
dyscostman::threadgroup::join_all
void join_all()
Join all threads in the group that have not yet been joined.
Definition threadgroup.h:33
dyscostman::threadgroup::empty
bool empty() const
Get state of thread group.
Definition threadgroup.h:45
dyscostman::threadgroup::~threadgroup
~threadgroup()
Destructor.
Definition threadgroup.h:18
dyscostman::threadgroup::create_thread
void create_thread(T threadFunc)
Create a new thread that will execute the given functor.
Definition threadgroup.h:26
dyscostman::threadgroup::threadgroup
threadgroup()
Constructor.
Definition threadgroup.h:16
dyscostman::threadgroup::_threads
std::vector< std::thread > _threads
Definition threadgroup.h:48
dyscostman
Definition bytepacker.h:7