代码来源:codeproject

1) 步骤一
#include "ThreadPool.h"
2)步骤二
从IRunObject派生自己的处理类
class CMyRunObject : public IRunObject
{
public:
 CMyRunObject();
 ~CMyRunObject();
 void Run();
 void Initialize()
 {
  // 初始化
 }
 
 bool AutoDelete()
 {
  // 是否自动删除(线程运行完后,自动删除IRunObject对象
  return true;
 }
 
 void DeleteInstance()
 {
  // 删除实例,当作析构来用
  delete this;
 }
};

派生类中必须实现的函数:Run, Initialize, AutoDelete, DeleteInstance
3)步骤三
启动线程池
CThreadPool m_Pool;
CMyRunObject *pRunObject = new CMyRunObject();
m_Pool.Run(pDeliver);
关闭线程池
m_pool.Destroy();
重启线程池
m_pool.Destroy();
m_pool.SetPoolSize(10);  // 池的初始线程数量
m_pool.SetPoolMaxSize(100); // 池的最大线程数
m_pool.Create();