#ifndef THREAD_POOL_H #define THREAD_POOL_H #include #include #include #include #include #include #include namespace zsy { class ThreadPool { std::vector threads; // 工作线程 std::queue > tasks; // 任务队列 mutable std::recursive_mutex queueMutex; // 保护任务队列的互斥锁 std::condition_variable_any taskCondition; // 任务通知条件变量 std::string name; // 0-->不可用,1-->已启动,2-->已关闭 uint8_t status; // 线程池停止标志 uint16_t threadCount; // 线程池停止标志 std::shared_mutex status_mtx; void addTask(const std::function &task); void createThread(); public: explicit ThreadPool(std::string name,uint16_t threadCount = std::thread::hardware_concurrency() * 2); void submit(const std::function &task); ~ThreadPool(); ThreadPool(const ThreadPool &) = delete; ThreadPool &operator=(const ThreadPool &) = delete; ThreadPool(ThreadPool &&) = delete; ThreadPool &operator=(ThreadPool &&) = delete; }; } // zsy #endif //THREAD_POOL_H