Terminating and unloading a module with the terminateAndUnload function

The terminateAndUnload function takes the same parameters and returns the same values and error codes as the unload routine. See the unload routine in Technical Reference: Base Operating System and Extensions, Volumes 1 & 2 for more information.

Format

#include <load.h>
int terminateAndUnload(int (*FunctionPointer)());

Description

The terminateAndUnload function performs any C++ termination that is required and unloads the module (shared library). The function pointer returned by the loadAndInit routine is used as the parameter for the terminateAndUnload function. If this is the last time the shared library is being unloaded, any C++ termination is performed for this shared library and any other shared libraries that are being unloaded for the last time as well. The terminateAndUnload function ensures that the shared library is only terminated once, even if dlclose is used to unload the library too. The order of termination is the reverse order of initialization performed by the loadAndInit function. If any uncaught exceptions occur during the C++ termination, the termination is stopped and the shared library is unloaded.

If the loadAndInit function is called more times for a shared library than terminateAndUnload, the shared library will never have the C++ termination performed. If you rely on the C++ termination being performed at the time the terminateAndUnload function is called, ensure the number of calls to the terminateAndUnload function matches the number of calls to the loadAndInit function. If any shared libraries loaded with the loadAndInit function are still in use when the program exits, the C++ termination is performed.

If the terminateAndUnload function is used to unload shared libraries not loaded with the loadAndInit function, no termination will be performed.

Parameters

FunctionPointer
Specifies the name of the function returned by the loadAndInit function.

Return values

Successful completion of the terminateAndUnload function returns a value of 0, even if the C++ termination was not performed and the shared library was not unloaded because the shared library was still in use.

If the terminateAndUnload function fails, it returns a value of -1 and sets errno to indicate the error.