# threadpool **Repository Path**: naught/threadpool ## Basic Information - **Project Name**: threadpool - **Description**: 基于C++11线程池。 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 1 - **Created**: 2023-06-06 - **Last Updated**: 2026-08-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ThreadPool A lightweight C++ thread pool implementation. ## Features - **Fixed-size Thread Pool**: Create a thread pool of a specified size - **Global Thread Pool**: Provide a globally shared thread pool instance - **Thread Status Monitoring**: Support querying thread pool size, idle thread count, and busy thread count - **Intelligent Task Management**: Automatically assign tasks to worker threads ## Quick Start ### Requirements - C++11 or higher - CMake 3.10+ ### Build Project ```bash mkdir build cd build cmake .. make ``` ### Usage Example ```cpp #include "threadpool.h" #include int main(int argc, char *argv[]) { // Create thread pool, specify number of threads auto pool = threadpool::create(4); // Submit task pool->submit([] { // Task logic }); // Get thread pool status std::cout << "Thread pool size: " << pool->size() << std::endl; std::cout << "Idle threads: " << pool->idle() << std::endl; std::cout << "Busy threads: " << pool->busy() << std::endl; // Use global thread pool auto globalPool = threadpool::global(); return 0; } ``` ## API Reference ### Core Methods - `static std::shared_ptr create(std::size_t size)` - Create a new thread pool - `static std::shared_ptr global()` - Get the global thread pool instance - `std::size_t size() const` - Get total thread pool size - `std::size_t idle() const` - Get number of idle threads - `std::size_t busy() const` - Get number of busy threads ### Submit Tasks Submit tasks to the thread pool for execution via the `submit()` method: ```cpp pool->submit([] { // Your task code }); ``` ## License This project is licensed under the MIT License.