ExitThread

  VOID ExitThread(dwExitCode)    
  DWORD dwExitCode; /* exit code for this thread */

The ExitThread function ends a thread.

Parameters

dwExitCode

Specifies the exit code for this thread.

Return Value

This function does not return a value.

Comments

ExitThread is the preferred method of exiting a thread. When this function is called (either explicitly or by returning from a thread procedure), the current thread's stack is deallocated and the thread terminates. If the thread is the last thread in the process when this function is called, the thread's process enters the signaled state and its termination status is updated). DLLs are not notified as a result of a call to ExitThread.

ExitProcess, ExitThread, CreateThread, and a process that is starting (as the result of a CreateProcess call) are serialized between each other within a process. Only one of these events can happen in an address space at a time. This means that:

During process startup and DLL initialization routines, new threads may be created, but they will not begin execution until DLL initialization is done for the process.

Only one thread in a process may be in a DLL initialization or detach routine at a time.

ExitProcess will block until no threads are in their DLL initialization or detach routines.

See Also

CreateProcess, CreateThread, ExitProcess, ExitThread, TerminateThread