Skip to content

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

Merged
jkotas merged 8 commits into
dotnet:mainfrom
eduardo-vp:fix-macos-thread-name
Apr 10, 2025
Merged

Name native threads before start (macOS/Native AOT)#114249
jkotas merged 8 commits into
dotnet:mainfrom
eduardo-vp:fix-macos-thread-name

Conversation

@eduardo-vp

Copy link
Copy Markdown
Member

Fixes #106464.

Copilot AI review requested due to automatic review settings April 4, 2025 00:57
@ghost ghost added the area-System.Threading label Apr 4, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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);

@dotnet-policy-service

Copy link
Copy Markdown
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
Comment thread src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs Outdated
if (!string.IsNullOrEmpty(_thread.Name))
{
// Name the underlying native thread to match the managed thread name.
_thread.ThreadNameChanged(_thread.Name);

@jkotas jkotas Apr 4, 2025

Copy link
Copy Markdown
Member

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.

Comment thread src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs Outdated
@jkotas

jkotas commented Apr 7, 2025

Copy link
Copy Markdown
Member

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

eduardo-vp commented Apr 9, 2025

Copy link
Copy Markdown
Member Author

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
Comment thread src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs Outdated

@jkotas jkotas left a comment

Copy link
Copy Markdown
Member

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
@eduardo-vp
eduardo-vp deleted the fix-macos-thread-name branch April 10, 2025 06:48
@github-actions github-actions Bot locked and limited conversation to collaborators May 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants