function
<cstdlib>

at_quick_exit

int at_quick_exit (void (*func)(void));
extern "C" int at_quick_exit (void (*func)(void)) noexcept;extern "C++" int at_quick_exit (void (*func)(void)) noexcept;
Set function to be executed on quick exit
The function pointed by func is automatically called (without arguments) when quick_exit is called.

If more than one at_quick_exit function has been specified by different calls to this function, they are all executed in reverse order.

If a function registered with at_quick_exit throws an exception for which it does not provide a handler while called by quick_exit, terminate is automatically called (C++).

Notice that the at_quick_exit stack of functions is separate from the atexit stack (and each is triggered by different circumstances), but the same function may be passed to both functions so that it is called in both cases.

Particular library implementations may impose a limit on the number of functions that can be registered with at_quick_exit, but this cannot be less than 32 functions.

Parameters

function
Function to be called. The function shall return no value and take no arguments.

Return Value

A zero value is returned if the function was successfully registered.
If it failed, a non-zero value is returned.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/* at_quick_exit example */
#include <stdio.h>      /* puts */
#include <stdlib.h>     /* at_quick_exit, quick_exit, EXIT_SUCCESS */

void fnQExit (void)
{
  puts ("Quick exit function.");
}

int main ()
{
  at_quick_exit (fnQExit);
  puts ("Main function: Beginning");
  quick_exit (EXIT_SUCCESS);
  puts ("Main function: End");  // never executed
  return 0;
}

Output:

Main function: Beginning
Quick exit function.


Data races

Concurrently calling this function introduces no data races: Calls are properly synchronized at the process level, although notice that the relative order of calls from different threads is indeterminate.
Calls to at_quick_exit that do not complete before a call to quick_exit may not succeed (depends on particular library implementation).

Exceptions (C++)

No-throw guarantee: this function never throws exceptions.

See also