CWinThread class, do not use CloseHandle to release the kernel after use

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.