Can I call CloseHandle() immediately after _beginthreadex() succeeded?

♀尐吖头ヾ 提交于 2019-12-05 05:42:39

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.

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.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!