I have doubt regarding the CreateThread() function in C++.
What is the importance of the threadId parameter in this function?
And are we able to create same thread( same name) using the same threadId. like
DWORD threadId = 0;
CreateThread(NULL, 0, Thread1, NULL,0, &threadId);
CreateThread(NULL, 0, Thread1, NULL,0, &threadId);
This way is possible? What will be the value contain in the threadId? By doing the above codding , Is the second thread creation will over write the threadId value of first thread?
You don’t need the
threadIdfor manipulating the thread if you hold the handle; however, you might choose to retain the IDs instead and then using the handles obtained byOpenThread. (This also works between processes, the only way you can “transfer” a handle to your thread to a different process byOpenThreading the ID there).You can also use the ID for distributing jobs to your threads (although you can just make up your own identifier).
And last but not least, there are moments you really need the thread ID, such as when calling the
PostThreadMessagefunction.