-
Notifications
You must be signed in to change notification settings - Fork 6k
update volatile information #8617
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
Conversation
Fixes #5763 Relies on dotnet/samples#412
closing and reopening to force a new build (the samples PR is merged) |
[!INCLUDE[CSharplangspec](~/includes/csharplangspec-md.md)] | ||
[!code-csharp[declareVolatile](~/samples/snippets/csharp/language-reference/keywords/volatile/Program.cs#Volatile)] | ||
|
||
With the `volatile` modifier on the declaration of in place, you'll always get the same results (similar to the excerpt shown in the preceding code). However, without that modifier on the `_shouldStop` member, the behavior is unpredictable. The `DoWork` method may optimize the member access, resulting in reading stale data. Because of the nature of multi-threaded programming, the number of stale reads is unpredictable. Different runs of the program will produce somewhat different results. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think variable names were here but removed. I see double spaces in the first start of the sentence, two of them:
X X
on the declaration of in
- [C# Reference](../index.md) | ||
- [C# Programming Guide](../../programming-guide/index.md) | ||
- [C# Keywords](index.md) | ||
- [Modifiers](modifiers.md) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Links to the lock
keyword and xref to the Interlocked
would be useful here, for sure.
And maybe that blog post, as well:
https://blogs.msdn.microsoft.com/ericlippert/2011/06/16/atomicity-volatility-and-immutability-are-different-part-three/
Updated per feedback. It's ready for another look @Thraka |
The anchor tag was wrong for the volatile section.
2f4c735
to
c661fb3
Compare
LGTM! |
Fixes #5763
Relies on dotnet/samples#412