Who is responsible for calling CloseHandle () for handwriting

I have a class Classin which there is an element property HANDLE handlefor the stream (we can assume that at this point it is set to NULL). at some point, the method internally Classsends one of its own methods Class::threaded()(using another function that is external to the class itself, but here it does not matter) with CreateThread(). Then the calling thread can continue another function outside Class.

Since it CloseHandle()should be called for HANDLEreturning from CreateThread(), I was wondering if calling it from Class::threaded()just before it would return would be a worthy decision.

+4
source share
3 answers

Two main ways to deal with the flow. Usually you are wondering when the thread ends, you will need to hold a handle so you can figure it out. And, of course, you will close it after you discover the completion. Or you don’t care, fire-and-forget style or additional synchronization objects to signal the end of the stream function and / or you ask it to exit. In this case, you simply close the handle immediately after it starts.

Keep in mind that it is not necessary to keep the handle open to maintain flow, in case there is a source of confusion.

+13
source

, . , CloseHandle.

HANDLE , , , .

+5

You can close it as soon as you use it. Closing does not affect the flow. (The handle refers to the OS.)

+4
source

All Articles