Freigeben über


ExitThread (Compact 2013)

3/28/2014

This function ends a thread.

Syntax

VOID ExitThread(
  DWORD dwExitCode
);

Parameters

  • dwExitCode
    [in] Specifies the exit code for the calling thread. To retrieve a thread's exit code, use the GetExitCodeThread function.

Return Value

None.

Remarks

The preferred method of exiting from a thread is to return from the thread procedure so the system implicitly calls ExitThread, and C++ function cleanup occurs.

When ExitThread is called (explicitly or by returning from a thread procedure), the current thread's stack is deallocated and the thread terminates.

The entry-point function of all attached DLLs is invoked with a value indicating that the thread is detaching from the DLL.

If the thread is the main thread in the process when this function is called, the thread's process is also terminated.

If the primary thread calls the ExitThread function, the application exits.

The state of the thread object becomes signaled, releasing other threads waiting for the thread to terminate.

The thread's termination status changes from STILL_ACTIVE to the value of the dwExitCode parameter.

Terminating a thread does not necessarily remove the thread object from the OS. A thread object is deleted when the last handle to the thread is closed.

The ExitThread and CreateThread functions, as well as a process that starts 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.

The following list shows the restrictions during the process:

  • During process startup and DLL initialization routines, new threads can be created, but they do not begin execution until DLL initialization is done for the process.
  • In a process, only one thread at a time can be in a DLL initialization or detach routine.

Requirements

Header

winbase.h

Library

coredll.lib

See Also

Reference

Process and Thread Functions
CreateProcess
CreateThread
GetExitCodeThread