Windows API Reference

ExitThread Function

The ExitThread function terminates the calling thread and removes it from the process.


VOID ExitThread(
  [in] DWORD dwExitCode
);
                    

Parameters

  • dwExitCode

    [in] The exit status of the thread. Use the return value of the CreateThread function to specify the exit code.

Return Value

This function does not return a value.

Remarks

  • When a thread calls the ExitThread function, it is terminated. The thread's return value is the value of the dwExitCode parameter.
  • The system increments the exit thread count for the process.
  • The system invalidates the thread's handle.
  • The system frees the thread's stack and all the kernel resources that the thread owns.
  • The system sets the thread's exit status to the value of dwExitCode.
  • The system signals any threads that are waiting for the thread to terminate.
  • The system does not call the DLL_THREAD_DETACH notification for DLLs loaded into the process.
  • The system does not call the thread's exception handlers.
  • If the thread was created with a specific security descriptor, that descriptor is freed.
  • The system does not call the onexit functions.
  • If the thread is the last thread in a process, the process terminates. The system closes all open handles in the process and marks the process as signaled. The exit code for the process is the exit code of the last thread to terminate.
  • A thread cannot call ExitThread for another thread.
  • To terminate another thread, use the TerminateThread function. However, TerminateThread should be used with caution, as it can leave an application in an unstable state.

Requirements

Minimum supported client Windows 2000 Professional
Minimum supported server Windows 2000 Server
Header winuser.h (include windows.h)
Library User32.lib
DLL User32.dll