casacore
threadgroup.h
Go to the documentation of this file.
1 #ifndef DYSCO_THREADGROUP_H
2 #define DYSCO_THREADGROUP_H
3 
4 #include <stdexcept>
5 #include <thread>
6 #include <vector>
7 
8 namespace dyscostman {
9 
13 class threadgroup {
14  public:
19 
25  template <typename T>
26  void create_thread(T threadFunc) {
27  _threads.emplace_back(threadFunc);
28  }
29 
33  void join_all() {
34  for (std::thread &t : _threads) {
35  t.join();
36  }
37  _threads.clear();
38  }
39 
45  bool empty() const { return _threads.empty(); }
46 
47  private:
48  std::vector<std::thread> _threads;
49 };
50 
51 } // namespace dyscostman
52 
53 #endif
Group of threads.
Definition: threadgroup.h:13
void join_all()
Join all threads in the group that have not yet been joined.
Definition: threadgroup.h:33
bool empty() const
Get state of thread group.
Definition: threadgroup.h:45
~threadgroup()
Destructor.
Definition: threadgroup.h:18
void create_thread(T threadFunc)
Create a new thread that will execute the given functor.
Definition: threadgroup.h:26
threadgroup()
Constructor.
Definition: threadgroup.h:16
std::vector< std::thread > _threads
Definition: threadgroup.h:48