Is it possible to call CloseHandle () right after reaching _beginthreadex ()?

I am not interested in using the handle returned from _beginthreadex() . Is it safe to call CloseHandle() on it?

I believe that this is necessary to avoid memory leaks.

+6
source share
2 answers

Yes, you can close the descriptor as soon as you decide that you no longer need this descriptor. This will not affect thread execution. However, you should probably check if the thread was started at all before continuing.

The leaks that bother you are not memory leaks, they are leaks of system resources - they are usually much worse.

+9
source

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, you should not explicitly close the thread descriptor by calling the Win32 CloseHandle API. (For more details see http://msdn.microsoft.com/en-us/library/kdzttdcb(ar-sa).aspx .)

-1
source

Source: https://habr.com/ru/post/902194/


All Articles