Repository navigation
Clarify volatile memory ordering, loop hoisting, and Debug vs Release behavior (Fixes #25426) - #56650
Open
Manish-1kumar wants to merge 5 commits into
Conversation
jkotas
reviewed
Nov 2, 2026
jkotas
reviewed
Nov 3, 2026
jkotas
reviewed
Nov 3, 2026
…ile guide Generalize JIT compiler references to runtime to encompass execution modes such as Native AOT and remove redundant CPU register phrasing per maintainer feedback.
jkotas
reviewed
Nov 3, 2026
Reflects suggestion from @jkotas on PR dotnet#56650: CancellationTokenSource was introduced over 15 years ago and is standard practice across .NET. Fixes: dotnet#56650 (comment)
jkotas
reviewed
Nov 16, 2026
…er caching Per suggestion by @jkotas on PR dotnet#56650: processor registers are not the only mechanism used to cache values; clarify that the value is read on each loop iteration rather than reusing a previously read value. Fixes: dotnet#56650 (comment)
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The added note leaves the Debug-versus-Release confusion unexplained and needs an optimized-run example clarifying that Release does not guarantee an observable failure.
1 open issue
What changed in this PR
Clarifies the C# volatile example to explain why removing the modifier can produce unpredictable behavior, addressing the confusion reported in #25426.
Changes:
- Explains per-iteration reads, memory ordering, and how loop-read hoisting can cause an infinite loop.
- Notes that runtime conditions, hardware, and optimizations affect observed behavior.
- Recommends
CancellationTokenSourceandCancellationTokenfor cooperative cancellation.
| File | Description |
|---|---|
docs/csharp/language-reference/keywords/volatile.md |
Clarifies the worker-loop behavior and adds cancellation guidance. |
Review effort: Balanced
jkotas
approved these changes
Nov 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
Resolves #25426.
Clarifies the behavior of the worker thread code snippet in \docs/csharp/language-reference/keywords/volatile.md\ and explains why running the code without \�olatile\ may still appear to terminate predictably in standard debug test runs.
Changes Included
Internal previews
Build report