Skip to content

Latest commit

 

History

History
66 lines (45 loc) · 3.13 KB

endthread-endthreadex.md

File metadata and controls

66 lines (45 loc) · 3.13 KB
description title ms.date api_name api_location api_type topic_type f1_keywords helpviewer_keywords
Learn more about: _endthread, _endthreadex
_endthread, _endthreadex
4/2/2020
_endthread
_endthreadex
_o__endthread
_o__endthreadex
msvcrt.dll
msvcr80.dll
msvcr90.dll
msvcr100.dll
msvcr100_clr0400.dll
msvcr110.dll
msvcr110_clr0400.dll
msvcr120.dll
msvcr120_clr0400.dll
ucrtbase.dll
api-ms-win-crt-runtime-l1-1-0.dll
DLLExport
apiref
_endthread
endthreadex
_endthreadex
endthread
_endthread function
endthread function
terminating threads
endthreadex function
_endthreadex function
threading [C++], terminating threads

_endthread, _endthreadex

Terminates a thread; _endthread terminates a thread that's created by _beginthread and _endthreadex terminates a thread that's created by _beginthreadex.

Syntax

void _endthread( void );
void _endthreadex(
   unsigned retval
);

Parameters

retval
Thread exit code.

Remarks

You can call _endthread or _endthreadex explicitly to terminate a thread; however, _endthread or _endthreadex is called automatically when the thread returns from the routine passed as a parameter to _beginthread or _beginthreadex. Terminating a thread with a call to endthread or _endthreadex helps ensure proper recovery of resources allocated for the thread.

Note

For an executable file linked with Libcmt.lib, do not call the Win32 ExitThread API; this prevents the run-time system from reclaiming allocated resources. _endthread and _endthreadex reclaim allocated thread resources and then call ExitThread.

_endthread automatically closes the thread handle. (This behavior differs from the Win32 ExitThread API.) Therefore, when you use _beginthread and _endthread, don't explicitly close the thread handle by calling the Win32 CloseHandle API.

Like the Win32 ExitThread API, _endthreadex doesn't close the thread handle. Therefore, when you use _beginthreadex and _endthreadex, you must close the thread handle by calling the Win32 CloseHandle API.

Note

_endthread and _endthreadex cause C++ destructors pending in the thread not to be called.

By default, this function's global state is scoped to the application. To change this behavior, see Global state in the CRT.

Requirements

Function Required header
_endthread <process.h>
_endthreadex <process.h>

For more compatibility information, see Compatibility.

Libraries

Multithreaded versions of the C run-time libraries only.

Example

See the example for _beginthread.

See also

Process and environment control
_beginthread, _beginthreadex