redjack/libcork — pull request #34 by dcreager (2013-01-14 16:40:54+00:00)
Title: Process cleanup functions

The standard `atexit(3)` function lets you register a cleanup function that will be called just before a process exits. The order in which the cleanup functions are called is the reverse of the order that you register them. One common idiom I've been using it to register cleanup functions from within a [`CORK_INITIALIZER`](http://libcork.readthedocs.org/en/latest/attributes/#CORK_INITIALIZER) function. Since there's no guarantee about the order that those initialization functions are called, we end up with an unspecified order for the `atexit` cleanup functions, too.

To get around this we need a version of `atexit` that lets you explicitly declare the ordering, so that the cleanup functions are called in the right order, even if they're registered in a different order.