Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Name native threads before start (macOS/Native AOT) #114249

Merged
merged 8 commits into from
Apr 10, 2025

Conversation

eduardo-vp
Copy link
Member

Fixes #106464.

@Copilot Copilot bot review requested due to automatic review settings April 4, 2025 00:57
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs:140

  • The assignment to _startHelper._thread = this is repeated in several constructors wrapped in #if TARGET_OSX. Consider refactoring this repeated pattern into a helper method to reduce duplication and simplify maintenance.
_startHelper = new StartHelper(start);

Copy link
Contributor

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

@eduardo-vp eduardo-vp force-pushed the fix-macos-thread-name branch 2 times, most recently from 1d2f58a to 3f46bf2 Compare April 4, 2025 01:35
if (!string.IsNullOrEmpty(_thread.Name))
{
// Name the underlying native thread to match the managed thread name.
_thread.ThreadNameChanged(_thread.Name);
Copy link
Member

@jkotas jkotas Apr 4, 2025

Choose a reason for hiding this comment

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

ThreadNameChanged sets the OS thread name, and also notifies profiler and debugger on CoreCLR about the thread name change. These notifications are superfluous here. I am not sure whether it matters.

@jkotas
Copy link
Member

jkotas commented Apr 7, 2025

Do we need a test (https://github.com/dotnet/runtime/blob/main/src/libraries/System.Threading.Thread/tests/ThreadTests.cs)?

@eduardo-vp eduardo-vp changed the title Name native threads before start on macOS Name native threads before start (macOS/Native AOT) Apr 7, 2025
@eduardo-vp eduardo-vp force-pushed the fix-macos-thread-name branch from 38f7487 to 9efae7c Compare April 9, 2025 01:28
@eduardo-vp eduardo-vp force-pushed the fix-macos-thread-name branch from 9efae7c to 18c9010 Compare April 9, 2025 01:40
@eduardo-vp
Copy link
Member Author

eduardo-vp commented Apr 9, 2025

Since checking the native thread name is platform specific rather than cross-platform and also there were errors in some Windows legs about not finding the native methods in kernel32.dll, I think we could merge this change without adding a test. It was manually validated for OSX/Native AOT.

@eduardo-vp eduardo-vp requested review from jkotas and kouvel April 9, 2025 22:37
Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

Thanks!

@jkotas jkotas merged commit c272e34 into dotnet:main Apr 10, 2025
140 of 142 checks passed
@eduardo-vp eduardo-vp deleted the fix-macos-thread-name branch April 10, 2025 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setting Thread.Name before Start() not working on macOS
2 participants