views:

629

answers:

2

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.

+7  A: 

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.

ctacke
+1, this way you won't get false positives when you use AppVerifier.
Paul Betts
+1  A: 

CreateThread function make reference count +2, CloseHandle only make reference count -1, when thread function finished, system will make reference count -1.

Yigang Wu