AtUnload

(Designed for drivers) Registers a function that is called if the NLM is unloaded with the UNLOAD command

Local Servers:nonblocking
Remote Servers:N/A
Classification:3.x, 4.x, 5.x, 6.x
Service:Thread

Syntax

  #include <nwthread.h>  
   
  int AtUnload  (  
     void   (*func) (void)); 
  

Parameters

func
(IN) Points to the function to be registered.

Return Values

The following table lists return values and descriptions.

Value

Hex

Name

Description

0

(0x00)

ESUCCESS

Registration was successful.

–1

 

EFAILURE

Function was already registered.

Remarks

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.

See Using AtUnload() functions: Example (NDK: Sample Code).

See Also

atexit, exit, _exit, ExitThread