Skip to content

Conversation

BillWagner
Copy link
Member

Fixes #5763

Relies on dotnet/samples#412

@BillWagner BillWagner requested a review from Thraka October 24, 2018 21:53
@BillWagner
Copy link
Member Author

closing and reopening to force a new build (the samples PR is merged)

@BillWagner BillWagner closed this Oct 24, 2018
@BillWagner BillWagner reopened this Oct 24, 2018
[!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.
Copy link
Contributor

@Thraka Thraka Oct 24, 2018

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)
Copy link
Contributor

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/

@BillWagner
Copy link
Member Author

Updated per feedback. It's ready for another look @Thraka

The anchor tag was wrong for the volatile section.
@BillWagner BillWagner force-pushed the update-volatile-keyword branch from 2f4c735 to c661fb3 Compare October 25, 2018 19:29
@Thraka
Copy link
Contributor

Thraka commented Oct 25, 2018

LGTM!

@BillWagner BillWagner merged commit a9bf7c7 into dotnet:master Oct 25, 2018
@BillWagner BillWagner deleted the update-volatile-keyword branch December 5, 2018 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants