[email protected], le mar. 03 mars 2026 04:08:15 +0000, a ecrit: > #### POSIX-5: Last thread's `pthread_exit` skips TSD destructors (MEDIUM) > > **POSIX** (`pthread_exit`, DESCRIPTION): > "After all cancellation cleanup handlers have been executed, if the thread > has any thread-specific data (whether associated with key type tss_t or > pthread_key_t), appropriate destructor functions shall be called in an > unspecified order." > > **Implementation** (`htl/pt-exit.c:58-65`): > ```c > if (atomic_fetch_add_relaxed (&__pthread_total, -1) == 1) > exit (0); // skips __pthread_destroy_specific below > __pthread_destroy_specific (self); > ``` > > When the last thread calls `pthread_exit`, the `exit(0)` at line 62 > terminates the process before `__pthread_destroy_specific` runs at line 65. > POSIX requires all TSD destructors to complete before process exit. > > #### POSIX-5 Proposed Fix: Move TSD destruction before last-thread check > > Move `__pthread_destroy_specific(self)` above the `__pthread_total` > decrement, consistent with `__call_tls_dtors` and `__libc_thread_freeres` > which are already called before the check: > > ```c > /* Destroy any thread specific data. */ > __pthread_destroy_specific (self); > > if (atomic_fetch_add_relaxed (&__pthread_total, -1) == 1) > exit (0); > ```
Indeed! Fixed so. Samuel
