ExitThread is the preferred method of exiting a thread in C code. However, in C++ code, the thread is exited before any destructors can be called or any other automatic cleanup can be performed. Therefore, in C++ code, you should return from your thread function.
From msdn:
TerminateThread is a dangerous function that should only be used in the most extreme cases. You should call TerminateThread only if you know exactly what the target thread is doing, and you control all of the code that the target thread could possibly be running at the time of the termination. For example, TerminateThread can result in the following problems:
•If the target thread owns a critical section, the critical section will not be released.
•If the target thread is allocating memory from the heap, the heap lock will not be released.
•If the target thread is executing certain kernel32 calls when it is terminated, the kernel32 state for the thread's process could be inconsistent.
•If the target thread is manipulating the global state of a shared DLL, the state of the DLL could be destroyed, affecting other users of the DLL.
Study these implementations of thread functions. If the thread has to perform a one off action you may just fall through the thread function and wait on it's handle for completion.
If the thread has to perform repeated functions in a loop or block waiting for events you need to signal the thread to exit by some other mechanism.
http://www.bogotobogo.com/cplusplus/multithreading_win32A.php[
^]
Creating Threads using the CreateThread() API[
^]