此线程池所依赖的线程类,请参看《一个Windows C++的线程类实现》:
http://blog.csdn.net/huyiyang2010/archive/2010/08/10/5801597.aspx
SystemThreadPool.h
SytemThreadPool.cpp
用法:
#include "Thread.h"#include "SystemThreadPool.h"class R : public Runnable{public: ~R() { } void Run() { printf("Hello World/n"); }};int _tmain(int argc, _TCHAR* argv[]){ CThreadPoolExecutor * pExecutor = new CThreadPoolExecutor(); pExecutor->Init(50); R r; for(int i=0;i<100;i++) { while(!pExecutor->Execute(&r)) { } } pExecutor->Terminate(); delete pExecutor; getchar(); return 0;}
测试结果:
机器:
Intel(R) Core(TM)2 Duo CPU
E8400 @ 3.00GHz
2G内存
对于100个任务并且每个任务包含10000000个循环,任务中无等待:
线程池耗时:2203时间片
from:http://blog.csdn.net/huyiyang2010/article/details/5820548