上传者: zt_xcyk 
                                    |
                                    上传时间: 2022-02-24 08:40:57
                                    |
                                    文件大小: 5KB
                                    |
                                    文件类型: -
                                
                            
                                
                            
                                一个简单的线程池示例,可以自定义线程数量和执行任务,代码简洁可扩展性强。在使用上也很方便。下面是一个简单的调用
int main()
{
 xcyk::ThreadPool threadPool("xcyk");
 SYSTEM_INFO SystemInfo;
 GetSystemInfo(&SystemInfo;);
 DWORD theadnum = SystemInfo.dwNumberOfProcessors + 2;
 threadPool.setMaxQueueSize(10);
 threadPool.start(theadnum);
 for (int i = 0; i < 50; ++i)
 {
  auto task = bind(Test, i);
  threadPool.run(task);
 }
 getchar();
 return 0;
}