[all-commits] [llvm/llvm-project] 15cff9: [libc] Make it possible to join the main thread (#...

Pavel Labath via All-commits all-commits at lists.llvm.org
Thu Sep 17 01:14:35 PDT 2026


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

  Changed paths:
    M libc/src/__support/threads/linux/thread.cpp
    M libc/startup/linux/CMakeLists.txt
    M libc/startup/linux/do_start.cpp
    M libc/test/integration/src/pthread/CMakeLists.txt
    M libc/test/integration/src/pthread/pthread_getattr_np_test.cpp
    A libc/test/integration/src/pthread/pthread_join_main_test.cpp

  Log Message:
  -----------
  [libc] Make it possible to join the main thread (#221177)

Joining the main thread currently crashes because its ThreadAttributes
has a null platform_data pointer, causing Thread::wait() to dereference
a null futex.

While this is not a frequently used feature, it is supported by other
implementations, and I believe it is required by POSIX (the exec page
says that the main thread is created in a joinable state, and neither
pthread_join nor pthread_exit mention them not working on the main
thread).

This patch sets up the main thread attributes during startup:
- allocate a static futex for the main thread's clear_tid and point
platform_data to it
- invoke set_tid_address to have the kernel clear the futex and wake
waiters on thread termination
- mark the main thread as joinable (it was previously defaulting to
detached)

The test for this functionality exposed the bug where the thread return
value is not preserved (and therefore not passed to pthread_join) for
threads exiting via pthread_exit, so I fix that as well.

This patch required accessing the CLEAR_TID_VALUE constant from multiple
files, but I couldn't find a suitable header to place it in. Instead of
creating a new one, I just delete the constant, as we don't really care
about its value -- only that it is not zero.

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