Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it reasonable to call CloseHandle() on a thread before it terminates?

I'd like to just create a thread, then call CloseHandle immediately and let the thread die on its own so that I don't have to do extra clean-up work in the 'original' thread (not that cleanup is hard in itself, but it means a fair amount of extra book-keeping which I'd like to avoid).

MSDN says that calling CloseHandle() on a thread doesn't terminate the thread, but it's not clear to me whether that means I'm really allowed to do this or not.

like image 435
John Bartholomew Avatar asked Jan 07 '09 00:01

John Bartholomew


1 Answers

Not only is it reasonable, not doing it is a handle leak. Generally I close it immediately after creating the thread unless I'm going to need it elsewhere.

like image 79
ctacke Avatar answered Sep 19 '22 22:09

ctacke