AtUnload
(Designed for drivers) Registers a function that is called if the NLM is unloaded with the UNLOAD command
#include <nwthread.h>
int AtUnload (
void (*func) (void));
The following table lists return values and descriptions.
WARNING:AtUnload was designed for use with drivers when an NLM is unloaded with the UNLOAD command. Do not use it as a cleanup routine for NLM applications. CLIB context does not exist for a thread that is running an atexit or AtUnload routine, and a server abend may result.
The cleanup routine to be run at NLM unload time should be registered as a signal handler using signal with the condition SIGTERM. This signal handler can use the thread group ID from the main NLM to switch to a CLIB context, allowing it to call any CLIB function. Ensure that the signal handler routine always restores the original thread group ID before exiting. Also take care that the main NLM does not exit before the signal handler exits. You can do this with a global variable modified by the signal handler, which is monitored by the main NLM before exiting (see GetThreadGroupID and SetThreadGroupID).
The AtUnload function is passed the address of a function to be called when the NLM is unloaded. Such functions can use only NLM (OS) level context.
Only one function can be registered with AtUnload.