#ifndef RADIX_RADIXPARA_THREAD_POOL_HH_ #define RADIX_RADIXPARA_THREAD_POOL_HH_ #include #include #include #include #include #include #include #include #include #include "radixcore/visibility.hh" namespace radix { class RADIX_PUBLIC ThreadPool { public: typedef std::unique_lock ThreadLock; /** * @brief ThreadPool default constructs with hardware_concurrency */ ThreadPool(); /** * @brief ThreadPool constructs ThreadPool with some number of threads * @param numThreads size_t number of threads */ explicit ThreadPool(size_t numThreads); ~ThreadPool(); template std::future::type> queue(FunctionType &&func, ArgumentList &&... args); /** * @brief threads retrieve const reference to list of threads * @return const std::vector& */ const std::vector &threads() const { return mWorkers; } private: // initializes with number of threads void init(size_t numThreads); // need to keep track of threads so we can join them std::vector mWorkers; // the task queue std::queue> mTasks; // synchronization for the task queue std::mutex mQueueMutex; // thread conditional std::condition_variable mCondition; // thread pool halt bool mStop; }; // class ThreadPool } // namespace radix // Include template implementation #include "radixpara/threadpool.i.hh" #endif /** RADIX_RADIXPARA_THREAD_POOL_HH_ */