Gendarme's concurrency rules are located in the Gendarme.Rules.Concurrency.dll assembly. Latest sources are available from anonymous SVN (http://anonsvn.mono-project.com/viewcvs/trunk/mono-tools/gendarme/rules/Gendarme.Rules.Concurrency/) (tarball (http://anonsvn.mono-project.com/viewcvs/trunk/mono-tools/gendarme/rules/Gendarme.Rules.Concurrency.tar.gz?view=tar)).
Table of Contents
Rules
DoubleCheckLockingRule
This rule is used to check for the double-check pattern in multi-threaded code and warns of its incorrect usage. For more information about the double checking problem, see the Double Checked Locking (http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html) article.
Bad example:
public static Singleton Instance { get { if (instance == null) { lock (syncRoot) { if (instance == null) instance = new Singleton (); } } return instance; } }
Good example:
public static Singleton Instance { get { lock (syncRoot) { if (instance == null) instance = new Singleton (); } return instance; } }
NonConstantStaticFieldsShouldNotBeVisibleRule
This rule warns if a non constant public static field is detected. In a multi-threaded environment access to those fields needs to be synchronized.
Bad example:
class HasPublicStaticField { public static ComplexObject Field; }
Good examples:
class FieldIsReadonly { public readonly static ComplexObject Field = new ComplexObject(); } class UseThreadStatic { [ThreadStatic] public static ComplexObject Field; public static InitializeThread () { if (Field == null) Field = new ComplexObject (); } }
WriteStaticFieldFromInstanceMethodRule
This rule is used to check for instance methods that writes values in static fields. This may cause problem when multiple instance of the type exists and when used in multithreaded applications.
Bad example:
static int default_value; public int Value { get { if (default_value == 0) default_value = -1; return (value > default_value) ? value : 0; } }
Good example:
static int default_value = -1; public int Value { get { return (value > default_value) ? value : 0; } }
Feedback
Please report any documentation errors, typos or suggestions to the Gendarme Google Group (http://groups.google.com/group/gendarme). Thanks!


