//说明, 这段代码我用了很久, 我删除了自动调整规模的代码(因为他还不成熟)
/****************************************************************** 【程序编程相关:Digester can not par】 【推荐阅读:[随文杂记]路......】* thread pool for win32 【扩展信息:用SnapIt 7.12 捕捉屏幕窗口中】 * vc++ 6, bc++ 5.5(free), gcc(free) * update : 2004.6.9 llbird wushaojian@21cn.comuse:
1): void threadfunc(void *p) { //... } threadpool tp; for(i=0; i<100; i++) tp.call(threadfunc);threadpool tp(20);//20为初始线程池规模
tp.call(threadfunc, lppara); tp.adjustsize(50);//增加50 tp.adjustsize(-30);//减少30 2): class mythreadjob : public threadjob //线程对象从threadjob扩展 { public: virtual void dojob(void *p)//自定义的虚函数 { //.... } }; mythreadjob mt[10]; threadpool tp; for(i=0; i<100 i++) tp.call(mt + i);//tp.call(mt + i, para);*******************************************************************/
#ifndef _threadpool_h_ #define _threadpool_h_#pragma warning(disable: 4530)
#pragma warning(disable: 4786)#include <cassert>
#include <vector> #include <queue> #include <windows.h> class threadjob //工作基类 { public: //供线程池调用的虚函数 virtual void dojob(void *ppara) = 0; };... 下一页