CloseHandle? 
Author Message
 CloseHandle?

Hi there,

do i have to CloseHandle(hThread) after CreateThread ?
like
hThread = ::CreateThread(....)
..

CloseHandle(hThread).

i ask that because i don't know when to CloseHandle...

thank you very much!



Thu, 03 Mar 2005 06:11:21 GMT  
 CloseHandle?
Hello,

After creating your thread, if you aren't going to stash a reference to it
for later use, then yes, immediately close the handle.

One word of caution however, per CreateThread's documentation:
"A thread that uses functions from the C run-time libraries should use the
beginthread and endthread C run-time functions for thread management rather
than CreateThread and ExitThread. Failure to do so results in small memory
leaks when ExitThread is called."

Regards,
Mike


Quote:
> Hi there,

> do i have to CloseHandle(hThread) after CreateThread ?
> like
> hThread = ::CreateThread(....)
> ..

> CloseHandle(hThread).

> i ask that because i don't know when to CloseHandle...

> thank you very much!



Thu, 03 Mar 2005 06:31:30 GMT  
 CloseHandle?

Quote:
> Hi there,

> do i have to CloseHandle(hThread) after CreateThread ?
> like
> hThread = ::CreateThread(....)
> ..

> CloseHandle(hThread).

> i ask that because i don't know when to CloseHandle...

Yes, you do.  You probably shouldn't be using CreateThread though - using
_beginthread or _beginthreadex unless you're absolutely certain that
CreateThread is right for you.

-cd



Thu, 03 Mar 2005 06:31:24 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. CloseHandle not freeing file (occasionally)

2. CloseHandle not Releasing File

3. CloseHandle

4. CloseHandle() - A memory leak of handle

5. CloseHandle ?

6. Closehandle/DeleteFile problem

7. CloseHandle() and Fatal Error 0E

8. CloseHandle doesn't seem to work.

9. CloseHandle(); within the thread itself.

10. Must do "CloseHandle(hThread)" ?

 

 
Powered by phpBB® Forum Software