ExitThread
Terminates either the current thread or the NLM
- Local Servers:blocking
- Remote Servers:N/A
- Classification:3.x, 4.x, 5.x,
6.x
- Service:Thread
Syntax
#include <nwthread.h>
void ExitThread (
int action_code,
int status);
Parameters
- action_code
- (IN) Specifies action code:
TSR_THREAD (-1)-Terminate only the current thread.
EXIT_THREAD (0)-Terminate the current thread; if
the current thread is also the last thread, terminate the NLM.
EXIT_NLM (1)-Terminate the entire NLM.
- status
- (IN) Specifies the return code of the NLM (currently,
the status is ignored).
Remarks
The action code determines whether to destroy the current
thread or the NLM:
- Action code TSR_THREAD terminates
only the current thread and should only be used in NLM applications
that are libraries (that is, they export symbols).
- Action code EXIT_THREAD is used to terminate
the current thread. If the current thread is also the only thread
of the NLM, the NLM itself is terminated.
- Action code EXIT_NLM is equivalent to the
exit function.
The ExitThread function causes a normal NLM termination consisting
of the following sequence of events:
- All threads in the NLM are destroyed.
- This function calls the atexit functions, which
are executed in "last-in, first-out" order.
- Cleanup routines are called for any libraries that
have registered cleanup routines and that the NLM has called. (For
more information, see Library
Concepts (NDK:
Program Management).)
- I/O buffers are flushed, and all second-level
files (opened with fopen, fdopen, freopen) are closed. Any files
created by tmpfile are deleted and purged.
- All screens are closed.
- All remote sessions are terminated.
- All other resources allocated by the NLM are freed.
- The NLM is unloaded.
Executing the following statement
return (completionCode);
from the function (including main) where a thread began is
equivalent to the following:
ExitThread (EXIT_THREAD, completionCode);