-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Do not hold SpinLock in fields marked as readonly #33773
Comments
Closely related / duplicative: dotnet/roslyn-analyzers#2811 |
Estimates:
|
Seems related to #33772 |
This analyzer has a long discussion here already: dotnet/roslyn-analyzers#2811 which @mavasani already approved. Do we want this issue to go through the dotnet/runtime API review process anyway? |
@carlossanlop I think a review would be good. The proposed rule only indirectly addresses the underlying problem, and we have a large number of related cases in #50389. |
Along those lines, storing
That'd be covered implicitly with non-read-only constraints, but should probably have a modified error description so that a warning / failure message makes reasonable sense. |
SpinLock
is a mutable struct, meant only for advanced scenarios. Accidentally making aSpinLock
fieldreadonly
can result in silent but significant problems, as any mutations to the instance (e.g. Enter, Exit) will be done on a compiler-generated copy and thus be ignored, making the lock an expensive nop. (It might make sense to extend this analyzer to additional mutable struct types where storing them in areadonly
field is likely a bug, e.g.GCHandle
.)Category: Reliability
The text was updated successfully, but these errors were encountered: