-
Notifications
You must be signed in to change notification settings - Fork 6k
Add warnings and guidance against using volatile keyword #47282
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
@copilot Can you start working on this again? |
Co-authored-by: BillWagner <[email protected]>
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.
Great start @copilot
I've got one comment for you to address.
Co-authored-by: BillWagner <[email protected]>
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.
This LGTM. I'll mark it ready for final review.
Fixes #23832
The
volatile
keyword documentation now includes prominent warnings about its limitations and strongly recommends safer alternatives for multithreaded programming.Changes Made
volatile
early in the documentSystem.Threading.Interlocked
operations for atomic operationslock
statements for mutual exclusionSystem.Threading.Volatile
class for explicit volatile operationsWhy These Changes
The C# community has identified that
volatile
is often misunderstood and misused, leading to subtle concurrency bugs. The existing documentation provided technical information but lacked guidance about when not to usevolatile
and what to use instead.What This Addresses
volatile
volatile
doesn't provide atomicity, prevent race conditions, or guarantee memory orderingvolatile
The documentation now follows the community consensus that
volatile
should be avoided in favor of more reliable alternatives while still providing the technical details for advanced scenarios.💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.
Internal previews