VC完成端口,创建多个线程时,怎么使用同一个线程函数??
初学windows下的完成端口,看到在获得服务器CPU个数后,依据CPU个数的2倍来创建服务线程,
有三点不明白,请教高手指点:
1: 创建多个线程时,为什么线程函数使用相同 ServerWorkerThread ??
2: 创建线程后,关闭线程句柄,以后对该线程的操作,是通过线程ID来操作的吗 ??
3: 单步进去看了,在每次CreateThread时,尽管线程函数相同,但是,产生的线程ID是相同的,但是相同的线程服务函数怎
么会有不同的线程ID ??
DWORD WINAPI ServerWorkerThread(LPVOID CompletionPortID);
for(i = 0; i < SystemInfo.dwNumberOfProcessors * 2; i++)
{
HANDLE ThreadHandle;
// Create a server worker thread and pass the completion port to the thread.
if((ThreadHandle = CreateThread(NULL,0,ServerWorkerThread,CompletionPort, 0, &ThreadID)) == NULL)
{
printf("CreateThread() failed with error %d\n", GetLastError());
return;
}
// Close the thread handle
CloseHandle(ThreadHandle);
}