-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Readonly Structs vs Classes have dangerous inconsistency - failed spin lock #17310
Comments
Got caught by this again today, readonly GCHandles never show as deallocated when free is called for the same reason |
https://gist.github.com/Drawaes/84704a1a8ce8eb9e3bca6ef364d8beb2 Simple example to repo the behavior |
Seems like an appropriate place for warning waves. |
The example you refer to does not use any kind of lock, am I missing something? |
@Korporal here's an example https://github.com/dotnet/coreclr/blob/master/src/mscorlib/shared/System/Buffers/ConfigurableArrayPool.cs#L169 It won't give you a compile error or runtime error if you make it readonly; it just won't lock |
Moving to IDE as suggestion for analyzer, since LDM concluded this should not be a compiler error. |
Any news on this? I think @GrabYourPitchforks had some ideas around this as well |
@mavasani Can this be moved to Roslyn-Analyzers? |
Tagging @stephentoub - I believe this is tracked by dotnet/roslyn-analyzers#2811 and there is already a WIP PR for it: dotnet/roslyn-analyzers#2831 |
Great. Closing out then. |
Version Used: Any
Steps to Reproduce:
Expected Behavior:
That the code is protected by the lock... or the compiler throws an error
Actual Behavior:
struct is copied and lock is taken on the copy no compiler warning
This seems like it should either not compile or should work. Because the readonly struct is copied the lock never actually works
will do nothing, apparently this is a known issue, that is defended against only by comments?
https://github.com/dotnet/coreclr/search?l=C%23&q=mutable+readonly&type=Code&utf8=%E2%9C%93
The text was updated successfully, but these errors were encountered: