#ifndef THREADPOOL_H #define THREADPOOL_H /// \cond // C headers // C++ headers #include #include #include #include // 3rd party headers /// \endcond // qtrocket headers #include "utils/TSQueue.h" /** * @brief A basic ThreadPool class */ class ThreadPool { public: ThreadPool(); ~ThreadPool(); template void submit(FunctionType f) { q.push(std::function(f)); } private: class JoinThreads { public: explicit JoinThreads(std::vector& inThreads) : threads(inThreads) {} ~JoinThreads() { for(auto& i : threads) { if(i.joinable()) { i.join(); } } } private: std::vector& threads; }; std::atomic_bool done; TSQueue> q; std::vector threads; JoinThreads joiner; void worker(); }; #endif // THREADPOOL_H