Skip to content

[6.3] Fix worker thread name handling on Linux#936

Open
KushalP wants to merge 4 commits intoswiftlang:release/6.3.1from
KushalP:release/6.3-worker-thread-name-cherry-pick
Open

[6.3] Fix worker thread name handling on Linux#936
KushalP wants to merge 4 commits intoswiftlang:release/6.3.1from
KushalP:release/6.3-worker-thread-name-cherry-pick

Conversation

@KushalP
Copy link
Copy Markdown
Contributor

@KushalP KushalP commented Mar 17, 2026

Explanation: The existing functionality is brittle on Linux, and the UX can be improved.
Scope: Narrow. Hard codes the thread name for queue workers.
Original PRs:

Risk: Very low.
Testing: CI

**Explanation:** The existing functionality is brittle on Linux, and the UX can be improved.
**Scope:** Narrow. Hard codes the thread name for queue workers.
**Original PRs:** swiftlang#934
**Risk:** Very low.
**Testing:** CI
@KushalP
Copy link
Copy Markdown
Contributor Author

KushalP commented Mar 17, 2026

@swift-ci please test.

@KushalP
Copy link
Copy Markdown
Contributor Author

KushalP commented Mar 17, 2026

@swift-ci Please test Windows platform.

@3405691582
Copy link
Copy Markdown
Member

Please incorporate changes from #937 otherwise this will break the build on that platform.

@KushalP KushalP marked this pull request as draft March 18, 2026 23:17
## Problem

PR swiftlang#934 (fd153d8) adds a `dispatch_thread_name` regression test that
asserts worker threads have a non-empty name. This test fails on
Amazon Linux 2 CI because `HAVE_PTHREAD_SETNAME_NP` is never set.

The root cause is CMake's `check_function_exists` attempting to link a
test program without `-lpthread`. On glibc < 2.34 (Amazon Linux 2
ships glibc 2.26), `pthread_setname_np` lives in a separate
`libpthread.so`[1].

The link fails, `HAVE_PTHREAD_SETNAME_NP` evaluates to false, and the
`pthread_setname_np` call in `queue.c` is compiled out. Worker threads
get no name, and the test assertion `strlen(thread_name) > 0` fails.

## Fix

Replace `check_function_exists` with `check_symbol_exists` against
`<pthread.h>`, and temporarily add `Threads::Threads` to
`CMAKE_REQUIRED_LIBRARIES` so the linker can resolve it.

This matches the pattern used by `llvm/cmake/config-ix.cmake`[2].

Guard the `dispatch_thread_name` test on `HAVE_PTHREAD_SETNAME_NP` so
it is only built when available.

## References

[1] https://github.com/bminor/glibc/blob/glibc-2.34/NEWS#L12-L16
[2] https://github.com/swiftlang/llvm-project/blob/8050c17d40a6bcf781c3fdf7120b8f2d3c6363ac/llvm/cmake/config-ix.cmake#L434-L443
@KushalP KushalP marked this pull request as ready for review March 19, 2026 16:55
@KushalP
Copy link
Copy Markdown
Contributor Author

KushalP commented Mar 19, 2026

@3405691582 I can do that as a follow up, once you've got it reviewed and merged into main.

@3405691582
Copy link
Copy Markdown
Member

Take #938 instead, in case I don't get time to figure out why the thread name test fails on OpenBSD.

@KushalP
Copy link
Copy Markdown
Contributor Author

KushalP commented Mar 19, 2026

@swift-ci please test.

@KushalP
Copy link
Copy Markdown
Contributor Author

KushalP commented Mar 23, 2026

Do not merge until #937 is merged to main and we've cherry picked those changes into this PR.

Here we just do this by token swapping, which feels a little dirty, but
fixing it otherwise would induce a larger diff to factor out and switch
on the pthread_get_name_np spelling variations.

Fixing this requires making setting the thread name non-Linux specific.
This is safe, because we've added cmake conditionals for the symbols.
@KushalP
Copy link
Copy Markdown
Contributor Author

KushalP commented Mar 24, 2026

@swift-ci please test.

@KushalP KushalP changed the base branch from release/6.3 to release/6.3.1 April 2, 2026 16:10
Copy link
Copy Markdown
Contributor

@al45tair al45tair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Co-authored-by: Alastair Houghton <alastair@alastairs-place.net>
@KushalP
Copy link
Copy Markdown
Contributor Author

KushalP commented Apr 3, 2026

@swift-ci please test.

@shahmishal
Copy link
Copy Markdown
Member

@swift-ci please test

@akmorrison
Copy link
Copy Markdown

Let's merge this once the 6.3.2 release window opens, the merge window for 6.3.1 is ending today

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants