以下是Microsoft Windows 网络编程的代码片段:
...
// Determine how many processors are on the system.
GetSystemInfo(&SystemInfo);
// Create worker threads based on the number of
// processors available on the system. For this
// simple case, we create one worker thread for each
// processor.
for (int i = 0; i < SystemInfo.dwNumberOfProcessors; i++)
{
// Create a server worker thread, and pass the
// completion port to the thread. NOTE: the
// ServerWorkerThread procedure is not defined
// in this listing.
HANDLE ThreadHandle = CreateThread(NULL, 0, ServerWorkerThread, CompletionPort, 0, NULL);
// Close the thread handle
CloseHandle(ThreadHandle);
}
...
我不明白为什么样本会直接关闭线程句柄。是否不需要存储它们(例如在 std::vector 中),以便稍后退出程序时终止所有工作线程?