#pragma once #ifndef THREAD_GROUP_H_MQSLWGKD #define THREAD_GROUP_H_MQSLWGKD #include #include namespace rpc { namespace detail { class thread_group { public: thread_group() {} thread_group(thread_group const &) = delete; void create_threads(std::size_t thread_count, std::function func) { for (std::size_t i = 0; i < thread_count; ++i) { threads_.push_back(std::thread(func)); } } void join_all() { for (auto &t : threads_) { if (t.joinable()) { t.join(); } } } ~thread_group() { join_all(); } private: std::vector threads_; }; } /* detail */ } /* rpc */ #endif /* end of include guard: THREAD_GROUP_H_MQSLWGKD */