[all-commits] [llvm/llvm-project] 667cfb: [libc] Reset thread-specific key value before invo...

Pavel Labath via All-commits all-commits at lists.llvm.org
Tue Sep 29 09:13:58 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 667cfbec38942e08bd67fa51cc05e63686dd01b9
      https://github.com/llvm/llvm-project/commit/667cfbec38942e08bd67fa51cc05e63686dd01b9
  Author: Pavel Labath <pavel at labath.sk>
  Date:   2026-09-29 (Tue, 29 Sep 2026)

  Changed paths:
    M libc/include/CMakeLists.txt
    M libc/include/llvm-libc-macros/CMakeLists.txt
    A libc/include/llvm-libc-macros/common-threads-macros.h
    M libc/include/llvm-libc-macros/limits-macros.h
    M libc/include/llvm-libc-macros/linux/unistd-macros.h
    A libc/include/llvm-libc-macros/threads-macros.h
    M libc/include/threads.yaml
    M libc/include/unistd.yaml
    M libc/src/__support/threads/CMakeLists.txt
    M libc/src/__support/threads/thread.cpp
    M libc/src/unistd/linux/CMakeLists.txt
    M libc/src/unistd/linux/sysconf.cpp
    M libc/test/integration/src/pthread/CMakeLists.txt
    M libc/test/integration/src/pthread/pthread_tss_test.cpp
    M libc/test/integration/src/threads/tss_test.cpp
    M libc/test/src/unistd/CMakeLists.txt
    M libc/test/src/unistd/sysconf_test.cpp

  Log Message:
  -----------
  [libc] Reset thread-specific key value before invoking destructor (#226134)

POSIX specifies that before calling a thread-specific key destructor,
the value of the key must be set to NULL (so pthread_getspecific returns
NULL from inside the destructor), and that the destructor pass must
repeat up to PTHREAD_DESTRUCTOR_ITERATIONS times if destructors
re-associate non-NULL values with keys.

This patch sets the key payload to nullptr prior to calling the
destructor, and loops over the key array up to the destructor iteration
limit as long as non-NULL values remain.

Along with that:
- introduce common-threads-macros.h to share the destructor iteration
count (4) between C (TSS_DTOR_ITERATIONS) and POSIX
(PTHREAD_DESTRUCTOR_ITERATIONS), and use it internally
- expose TSS_DTOR_ITERATIONS in threads.h
- expose and implement _SC_THREAD_DESTRUCTOR_ITERATIONS in sysconf

Note that I am not fixing the issue where a deleted key's destructor can
still run on thread exit if it was already cached in thread-local
storage. Fixing that properly will require tracking key generations or
validity across threads, so I'm leaving that for separate work
(#226122).

Fixes #194029.

Assisted-by: Gemini



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list