atexit

(Designed for drivers) Creates a list of functions that are executed on a "last-in, first-out" basis when the NLM exits normally or is unloaded

Local Servers:nonblocking
Remote Servers:N/A
Classification:ANSI
Service:Thread

Syntax

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

Parameters

func
(IN) Points to the function to be registered as an exit function.

Return Values

The following table lists return values and descriptions.

Value

Hex

Name

Description

0

(0x00)

ESUCCESS

Registration was successful.

-1

 

EFAILURE

Registration failed (32 functions are already registered).

Remarks

WARNING:The atexit function is designed to be used by drivers. Do not use it as an NLM cleanup routine. A server abend may result for this reason:

CLIB context does not exist for a thread that is running an atexit or AtUnload routine, since all NLM thread groups have been destroyed by the time these functions are called. Thus any saved thread group ID is invalid, and neither atexit nor AtUnload routines can use SetThreadGroupID to establish CLIB context for the thread. They therefore also cannot use NetWare API functions that require thread group or thread level context.

It is wise programing practice to have one exit point for a program, which could be the cleanup routine for the NLM. The "Remarks" section of AtUnload gives suggestions for developing a cleanup routine to be executed when an NLM is manually unloaded. The same routine can be used when exit is called from your program.

The atexit function is called when an NLM is terminated normally.

Successive calls to atexit create a list of functions that are executed on a "last-in, first-out" basis when:

  • The NLM calls exit.
  • The NLM calls ExitThread and it causes the NLM to be terminated.
  • The last thread in the NLM returns from its original function.
  • The NLM is unloaded with the UNLOAD command.

No more than 32 functions can be registered with atexit. The functions have no parameters and do not return values. Such functions can use only NLM (OS) level context.

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

See Also

AtUnload, exit, _exit, ExitThread