TSS_DTOR_ITERATIONSAuthors: Jay Ghiron
Date: 2026-10-09
Submitted against: C23
Status: Open
TSS_DTOR_ITERATIONSwhich expands to an integer constant expression representing the maximum number of times that destructors will be called when a thread terminates.
(C23 7.28.1 "Introduction" paragraph 3.)
For every thread-specific storage key which was created with a non-null destructor and for which the value is non-null,
thrd_exitsets the value associated with the key to a null pointer value and then invokes the destructor with its previous value. The order in which destructors are invoked is unspecified.If after this process there remain keys with both non-null destructors and values, the implementation repeats this process up to
TSS_DTOR_ITERATIONStimes.
(C23 7.28.5.5 "The thrd_exit function" paragraphs 2 and 3.)
In the definition of TSS_DTOR_ITERATIONS it is stated that
TSS_DTOR_ITERATIONS represents the maximum number of times that
destructors will be called, while in the definition of thrd_exit it
is stated that TSS_DTOR_ITERATIONS represents the maximum number of
times that destructors being called will be repeated. Those
definitions give contradictory maxima, which was the intent? For
example, if TSS_DTOR_ITERATIONS is defined as one would it be valid
to repeat calling the destructors?
Can TSS_DTOR_ITERATIONS be negative? There does not appear to be
anything specifically forbidding it, though the meaning of the text
defining TSS_DTOR_ITERATIONS would be unclear with such a
definition.
If the answer to question one is that the maximum described in the
definition of TSS_DTOR_ITERATIONS is correct, can
TSS_DTOR_ITERATIONS be zero?