Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 635
user1061590 Avatar asked Nov 23 '11 11:11

user1061590


1 Answers

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.

like image 93
sharptooth Avatar answered Nov 09 '22 16:11

sharptooth