When using AfxBeginThread () to open threads in VC + +, a pointer to the Cwinthead class is returned. But should the kernel resources be freed with CloseHandle after use?
In Windows core programming, when you use the ExitThread () function to terminate a thread, the system resources are cleaned up, but C + + resources (such as C + + class resources) are not destroyed. When you use the TerminateThread function to terminate a thread, the thread's stack resource is not destroyed. It is suggested that the best way to end the thread is to make the thread function exit normally. However, it is not known whether to use CloseHandle to shut down the system kernel object, which is the handle. and whether the delete CWinThread pointer is required.
On MSDN, there is a m_bautodelete variable in the CWinThread class that deletes itself at the end of the thread, and this value is set to True by default. Delete will execute the destructor of the class, and the system resources should be destroyed in the destructor. For example, the value of M_bautodelete is 1.
When the thread ends, in view of the value of the CWinThread class, found to be garbled, and so on, in fact, the object referred to by the Cwndthread pointer has been deleted. Such as:
CWinThread class, do not use CloseHandle to release the kernel after use