https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113401
--- Comment #7 from Iain Sandoe <iains at gcc dot gnu.org> --- (In reply to Florian Weimer from comment #6) > Sorry, pthread_cleanup_push is purely scope-based, like the existing > handler. It cannot be used to push a handler to some unscoped cleanup > function list that persists even after the current function returns. It's > also implemented as a macro, so it's not possible to emit it from builtin > expansion. Ah, then we have a documentation issue, because man pthread_cleanup_push(3) describes running the registered functions on thread cancellation or on thread_exit() [but not, unfortunately if the thread exits by returning - so still not ideal].