I'm not interested in using the handle returned from _beginthreadex()
. Is it safe to call CloseHandle()
on it immediately?
I believe this must be done to avoid memory leaks.
I'm not interested in using the handle returned from _beginthreadex()
. Is it safe to call CloseHandle()
on it immediately?
I believe this must be done to avoid memory leaks.
According to MSDN, you should not close the handle returned by __beginThreadEx: _endthread automatically closes the thread handle (whereas _endthreadex does not).Therefore, when using _beginthread and _endthread, do not explicitly close the thread handle by calling the Win32 CloseHandle API. (see http://msdn.microsoft.com/en-us/library/kdzttdcb(ar-sa).aspx for details.)
Yes, you can close the handle as soon as you decide you no longer need that handle. That won't affect thread execution. However you likely should check whether the thread has been started at all before you proceed.
The leaks you're concerned about are not memory leaks, they are system resources leaks - usually they are much worse.