请教完成端口操作,在创建多个线程时,线程函数可以相同吗?

thunder__god 2010-05-23 11:10:26
初学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);
}
...全文
114 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

6,849

社区成员

发帖
与我相关
我的任务
社区描述
Windows 2016/2012/2008/2003/2000/NT
社区管理员
  • Windows Server社区
  • qishine
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧