# ThreadPool **Repository Path**: levanliu/thread-pool ## Basic Information - **Project Name**: ThreadPool - **Description**: 使用C++ 17实现的线程池。 同时支持windows linux 和 macos平台 - **Primary Language**: C++ - **License**: Zlib - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 1 - **Created**: 2023-01-09 - **Last Updated**: 2024-06-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ThreadPool https://gitee.com/TristanHNU/thread-pool.git #### 介绍 基于 C++ 17 的线程池 linux ```sh sudo apt install build-essential gdb cmake git curl ``` windows ```windows 1、open shell to install chocolatey (need proxy $Env:http_proxy="http://127.0.0.1:7890" $Env:https_proxy="http://127.0.0.1:7890" ) 在powershell中安装chocolatey (https://community.chocolatey.org/packages/cmake.install) Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) choco install mingw --installargs 'ADD_MINGW_TO_PATH=System' choco install cmake.install choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System' ``` example ```cpp // Create a thread pool with 4 worker threads ThreadPool pool(4); // Enqueue some tasks std::vector> results; for (int i = 0; i < 50; i++) { results.emplace_back( pool.enqueue([i] { std::cout << "Hello from task " << i << std::endl; std::this_thread::sleep_for(std::chrono::seconds(1)); std::cout << "Task " << i << " completed" << std::endl; return i * i; })); } // Wait for all tasks to complete for (auto &result : results) std::cout << "Task completed with result: " << result.get() << std::endl; return 0; ```