{ //启动工作线程
unsigned long MaxWorkThread;
unsigned long threadcount;
DWORD dwThreadId;
HANDLE* hThread;
//读取配置文件中开启线程的数目
MaxWorkThread=GetConfigInt("Httpd","MaxWorkThread",2);
//0代表根据CPU数目设置线程数目 CPU数目*2+2
if(MaxWorkThread<1)
{
SYSTEM_INFO systemInfo;
GetSystemInfo(&systemInfo);
MaxWorkThread=systemInfo.dwNumberOfProcessors*2+2;
}
hThread=HeapAlloc(GetProcessHeap(),0,sizeof(HANDLE)*MaxWorkThread);
for(threadcount=0;threadcount<MaxWorkThread;threadcount++)
{
hThread[threadcount]=CreateThread(NULL,0,WorkerThread,hIOCP,0,&dwThreadId);
}
//等待工作线程退出,主线程进入阻塞状态
WaitForMultipleObjects(MaxWorkThread,hThread,TRUE,INFINITE);
for(threadcount=0;threadcount<MaxWorkThread;threadcount++)
{
CloseHandle(hThread);
}
HeapFree(GetProcessHeap(),0,hThread);
}
文章来源于领测软件测试网 https://www.ltesting.net/