Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: atexit(), dlclose() and more atexit()

> On Jun 29, 2020, at 5:13 PM, Kamil Rytarowski <> wrote:
>> <quote>
>> The atexit() function shall register the function pointed to by func, to be called without arguments at normal program termination. At normal program termination, all functions registered by the atexit() function shall be called, in the reverse order of their registration, except that a function is called after any previously registered functions that had already been called at the time it was registered. Normal termination occurs either by a call to exit() or a return from main().
>> </quote>
>> My reading of the standard here is that atexit() handlers are called at "normal program termination", and that "normal program termination" is explicitly defined as either a call to exit() or returning from main(), and thus any other call to atexit() handlers is expressly forbidden by the standard.
> There is no word "only", so it's unspecified.

Sorry, but that seems like a huge stretch.  Everything seems tied to the process "exit" path in the description of atexit().  Even in the APPLICATION USAGE section, they have the following informative text:

All functions registered by the atexit() function are called at normal process termination, which occurs by a call to the exit() function or a return from main() or on the last thread termination, when the behavior is as if the implementation called exit() with a zero argument at thread termination time.

...specifically, the "is as if" qualifier.  In my reading, if the enclosing program is not terminating, then atexit() handlers should not be called.

dlclose() does not initiate "normal program termination" (it's also specified in Issue 7, so I double-checked!), nor does it mention anything about being considered "normal program termination" from the perspective of the shared object that is being closed.

Can you point to another place in the standard that uses the "only" type wording to justify your reading of atexit()?

-- thorpej

Home | Main Index | Thread Index | Old Index