Many programs are written like this in the creation thread:
Threadhandle = createthread (null, 0 ,.....);
Closehandel (threadhandle );
1. The thread and the thread handle are not a single thing. The thread runs on the CPU... (not clear). The thread handle is a kernel object. We can use a handle to operate the thread, but the thread's lifecycle is different from that of the thread's handle. The life cycle of a thread is from the execution of a thread function to the Return. the life cycle of a thread handle is returned from createthread to your closehandle ().
2. A thread is a kernel object. The system maintains each kernel object. When the reference count of each kernel object is 0, the system releases the object from the memory, closehandle reduces the reference count of the thread object by 1. All kernel objects (including thread handle) are system resources and need to be paid back when they are used up. That is to say, closehandle must be disabled after use. Otherwise, your system's handle resources will soon be used up.
3. If you need to perform operations on this thread after createthread, such as changing the priority, waiting by other threads, and forcing termatethread, you need to save the handle and use it in closehandle. If you open a thread without interfering with it, createthread and then directly closehandle.
So closehandel (threadhandle );
If a thread handle object is closed, it means that I no longer use the handle, that is, I do not intervene in the thread corresponding to the handle. There is no end thread.
If you think there is one more variable, you can also write it:
Closehandel (createthread (null, 0 ,.....));