# WThreadPool **Repository Path**: fengxian21/wthread-pool ## Basic Information - **Project Name**: WThreadPool - **Description**: 基于C++语言编写的线程池 - **Primary Language**: C++ - **License**: BSD-3-Clause - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2021-11-01 - **Last Updated**: 2025-08-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # WThreadPool #### 介绍 基于C++语言编写的线程池,暂时采用有锁队列,有管理线程,在任务繁忙时会增加线程,在任务少时会减少线程以节省资源.该工程是跨平台的 #### 软件架构 软件架构说明 #### 安装教程 直接使用源码中LockQueue.hpp、WThreadPool.h、WThreadPool.cpp文件集成到自己的工程即可 #### 使用说明 1、void setMaxThreadNum(int maxNum),设置最大线程数 2、bool waitForDone(int waitMs),阻塞等待所以任务完成,可传入等待超时时间,若传入负值,则永久等待 3、void concurrentRun(Func func, Arguments... args),最关键的函数,传入任务函数,会在子线程中执行。该接口与std::thread是一致的,支持lambda表达式 示例: ``` int main() { WThreadPool threadPool; threadPool.setMaxThreadNum(10); cout << "the main thread pid: " << this_thread::get_id() << endl; for (int i = 0; i < 20; i++) { threadPool.concurrentRun([=] (int index) { cout << "the sub thread pid: " << this_thread::get_id() << " ,index is " << index << endl; }, i); } bool flag = threadPool.waitForDone(-1); cout << "get here to wait: " << flag << endl; return 0; } ```