Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8286623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:49:36+00:00 2026-06-08T11:49:36+00:00

Here is a code snippet from Network Programming for Microsoft Windows : … //

  • 0

Here is a code snippet from Network Programming for 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);
}
...

What I don’t understand is why the sample closes the thread handles straightaway. Is it not necessary to store them (for example in a std::vector) so you can terminate all the worker threads later when exiting your program?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T11:49:38+00:00Added an answer on June 8, 2026 at 11:49 am

    It is not necessary. From msdn on CloseHandle:

    Closing a thread handle does not terminate the associated thread or
    remove the thread object.
    Closing a process handle does not terminate
    the associated process or remove the process object. To remove a
    thread object, you must terminate the thread, then close all handles
    to the thread.
    For more information, see Terminating a Thread. To
    remove a process object, you must terminate the process, then close
    all handles to the process. For more information, see Terminating a
    Process.

    In practive self contained threads are often created with their handles immediately closed, this allowing resource release when thread exits.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a code snippet from my project: template<typename Second, typename First = const
Here is a code snippet from DirectShowNet library, used to open a video file:
FULL CLASS CODE HERE: http://pastebin.com/rdjDGLJS EDIT: Latest code snippet taken from original posters comment
Here's an ASPX code snippet from when I was trying to get multiple values
Here is a code snippet from my page: <input value=Search type=submit /><!-- whitespace --><span
here's my code snippet to start with: $url = $_SERVER[REQUEST_URI]; // gives /test/test/ from
I am trying to send email from Ant Script. here is the code snippet
Here's a code snippet from OpenJDK6's hotspot/src/share/vm/prims/unsafe.cpp (starting on line 1082): // JSR166 ------------------------------------------------------------------
Here's the code snippet: public static void main (String[]arg) { char ca = 'a'
Here is my code snippet where I'am taking confidence with initialization blocks class Father{

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.