A thread can be terminated in four ways:
The thread function returns. (This is highly recommended.)
The thread kills itself by calling the
ExitThread function. (Avoid this method.)
A thread in the same process or in another one calls the
TerminateThread function. (Avoid this method.)
The process containing the thread terminates. (Avoid this method.)
This section discusses all four methods for terminating a thread and describes what happens when a thread ends.
You should always design your thread functions so that they return when you want the thread to terminate. This is the only way to guarantee that all your thread’s resources are cleaned up properly.
Having your thread function return ensures the following: ...