-
Notifications
You must be signed in to change notification settings - Fork 3
Gendarme.Rules.Concurrency.ReviewLockUsedOnlyForOperationsOnVariablesRule(2.10)
Sebastien Pouliot edited this page Jan 22, 2011
·
2 revisions
Assembly: Gendarme.Rules.Concurrency
Version: 2.10
This rule checks if a lock is used only to perform operations on locals or fields. If the only purpose of that critical section is to make sure the variables are modified atomatically then the methods provided by System.Threading.Interlocked class will be more efficient.
Bad example:
lock (_lockObject) {
_counter++;
}
Good example:
Interlocked.Increment(_counter);
Bad example:
lock (_lockObject) {
_someSharedObject = anotherObject;
}
Good example:
Interlocked.Exchange(_someSharedObject, anotherObject);
Note that this page was autogenerated (3/17/2011 9:31:58 PM) based on the xmldoc comments inside the rules source code and cannot be edited from this wiki.
Please report any documentation errors, typos or suggestions to the
Gendarme Mailing List. Thanks!