atexit


Description:

[ Version ( deprecated_since = "2.32" , deprecated = true ) ]
public void atexit (VoidFunc func)

Warning: atexit is deprecated since "2.32".

Specifies a function to be called at normal program termination.

Note:

It is best to avoid atexit.

Since GLib 2.8.2, on Windows atexit actually is a preprocessor macro that maps to a call to the atexit function in the C library. This means that in case the code that calls atexit, i.e. atexit, is in a DLL, the function will be called when the DLL is detached from the program. This typically makes more sense than that the function is called when the GLib DLL is detached, which happened earlier when atexit was a function in the GLib DLL.

The behaviour of atexit in the context of dynamically loaded modules is not formally specified and varies wildly.

On POSIX systems, calling atexit (or atexit) in a dynamically loaded module which is unloaded before the program terminates might well cause a crash at program exit.

Some POSIX systems implement atexit like Windows, and have each dynamically loaded module maintain an own atexit chain that is called when the module is unloaded.

On other POSIX systems, before a dynamically loaded module is unloaded, the registered atexit functions (if any) residing in that module are called, regardless where the code that registered them resided. This is presumably the most robust approach.

As can be seen from the above, for portability it's best to avoid calling atexit (or atexit) except in the main executable of a program.

Parameters:

func

the function to call on normal program termination.


Namespace: GLib.Environment
Package: glib-2.0