VOID ExitThread (
DWORD Dwexitcode);
Dwexitcode Specify this thread end code
No return value
This function is somewhat like the exit () function in the C runtime library because he can be called at any time and will never return. Any code that is placed below this line is guaranteed not to be executed.
#define Win32_lean_and_mean#include <stdlib.h> #include <stdio.h> #include <windows.h>dword WINAPI ThreadFunc (LPVOID); void Anotherfunc (void); int main () {HANDLE Hthrd;dword ExitCode = 0;dword THREADID;HTHRD = CreateThread (Null,0,threadfunc, (LPVOID) 1,0,&threadid); if (HTHRD) {printf ("Thread launched\n");} for (;;) {BOOL RC;RC = GetExitCodeThread (Hthrd,&exitcode); if (rc && exitCode! = still_active) break;} CloseHandle (HTHRD);p rintf ("Thread returned%d\n", ExitCode); return exit_success;} DWORD WINAPI ThreadFunc (lpvoid N) { printf ("Thread running\n"); Anotherfunc (); return 0;} void Anotherfunc () {printf ("About to exit thread\n"); ExitThread (4);p rintf ("This would never printf\n");}
The thread that is executed after the thread is started is called the main threads (primary thread). Main thread two features. First, he is responsible for the logoff information loop in the GUI (Graphic User Interface) program. Second, the end of this thread (either because it is returned or because the call to ExitThread ()) causes all threads in the program to be forced to end, and the program ends. Other threads do not have the opportunity to do cleanup work.
Use mandatory means to end a process