Skip to content

Unify Thread.SpinWait/Yield/OptimalMaxSpinWaitsPerSpinIteration between CoreCLR and NativeAOT - #135138

Merged
jkotas merged 2 commits into
dotnet:mainfrom
EgorBo:unify-thread-spinwait-yield
Oct 6, 2026
Merged

jkotas merged 2 commits into
dotnet:mainfrom
EgorBo:unify-thread-spinwait-yield

Conversation

@EgorBo

@EgorBo EgorBo commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Move the managed implementation into shared Thread.cs and back it with native helpers in src/coreclr/runtime/MiscNativeHelpers.cpp, which is compiled into both runtimes. Delete the CoreCLR ThreadNative_SpinWait/ThreadNative_YieldThread QCalls and the GetOptimalMaxSpinWaitsPerSpinIteration FCALL, and the NativeAOT RhSpinWait/RhYield exports.

NativeAOT now reports the measured OptimalMaxSpinWaitsPerSpinIteration instead of a hard-coded 8.

Fixes dotnet/corert#4430

…en CoreCLR and NativeAOT

Move the managed implementation into shared Thread.cs and back it with native helpers in
src/coreclr/runtime/MiscNativeHelpers.cpp, which is compiled into both runtimes. Delete the
CoreCLR ThreadNative_SpinWait/ThreadNative_YieldThread QCalls and the
GetOptimalMaxSpinWaitsPerSpinIteration FCALL, and the NativeAOT RhSpinWait/RhYield exports.

NativeAOT now reports the measured OptimalMaxSpinWaitsPerSpinIteration instead of a hard-coded 8.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ac6fb33d-fc74-41c7-a804-75fbf616b155
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

Comment thread src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs Outdated
Call Thread.GetOptimalMaxSpinWaitsPerSpinIteration() directly from SpinWait and LowLevelSpinWaiter.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ac6fb33d-fc74-41c7-a804-75fbf616b155
@EgorBo

EgorBo commented Oct 6, 2026

Copy link
Copy Markdown
Member Author

@jkotas does it look good otherwise?

@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 commented Oct 6, 2026

Copy link
Copy Markdown
Member

/ba-g test failure is known error #135096

@jkotas
jkotas merged commit c0c1c33 into dotnet:main Oct 6, 2026
147 of 149 checks passed
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.

Port normalized equivalent of YieldProcessor from CoreCLR

2 participants