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
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ private void RunWorker()

try
{
#if TARGET_OSX || NATIVEAOT
// On other platforms, when the underlying native thread is created,
// the thread name is set to the name of the managed thread by another thread.
// However, on OS X and NativeAOT (across all OSes), only the thread itself can set its name.
// Therefore, by this point the native thread is still unnamed as it has not started yet.
Thread thread = Thread.CurrentThread;
if (!string.IsNullOrEmpty(thread.Name))
{
// Name the underlying native thread to match the managed thread name.
thread.ThreadNameChanged(thread.Name);
}
#endif
if (start is ThreadStart threadStart)
{
threadStart();
Expand Down
Loading