<Type Name="DoubleCheckLockingRule" FullName="Gendarme.Rules.Concurrency.DoubleCheckLockingRule">
  <TypeSignature Language="C#" Value="public class DoubleCheckLockingRule : Gendarme.Framework.Rule, Gendarme.Framework.IMethodRule" />
  <TypeSignature Language="ILAsm" Value=".class public auto ansi beforefieldinit DoubleCheckLockingRule extends Gendarme.Framework.Rule implements class Gendarme.Framework.IMethodRule, class Gendarme.Framework.IRule" />
  <AssemblyInfo>
    <AssemblyName>Gendarme.Rules.Concurrency</AssemblyName>
    <AssemblyVersion>2.11.0.0</AssemblyVersion>
  </AssemblyInfo>
  <Base>
    <BaseTypeName>Gendarme.Framework.Rule</BaseTypeName>
  </Base>
  <Interfaces>
    <Interface>
      <InterfaceName>Gendarme.Framework.IMethodRule</InterfaceName>
    </Interface>
  </Interfaces>
  <Attributes>
    <Attribute>
      <AttributeName>Gendarme.Framework.EngineDependency(typeof(Gendarme.Framework.Engines.OpCodeEngine))</AttributeName>
    </Attribute>
    <Attribute>
      <AttributeName>Gendarme.Framework.Problem("This method uses the potentially unreliable double-check locking technique.")</AttributeName>
    </Attribute>
    <Attribute>
      <AttributeName>Gendarme.Framework.Solution("Remove the check that occurs outside of the protected region.")</AttributeName>
    </Attribute>
  </Attributes>
  <Docs>
    <summary>
            This rule is used to check for the double-check pattern, often used when implementing
            the singleton pattern (1), and warns of potential incorrect usage.
            The original CLR (1.x) could not guarantee that a double-check would work correctly
            in multithreaded applications. However the technique does work on the x86 architecture,
            the most common architecture, so the problem is seldom seen (e.g. IA64).
            The CLR 2 and later introduce a strong memory model (2) where a double check for a
            <c>lock</c> is correct (as long as you assign to a <c>volatile</c> variable). This
            rule won't report a defect for assemblies targetting the 2.0 (and later) runtime.
            <list><item><term>1. Implementing Singleton in C#</term><description>
            http://msdn.microsoft.com/en-us/library/ms998558.aspx</description></item><item><term>2. Understand the Impact of Low-Lock Techniques in Multithreaded Apps</term><description>http://msdn.microsoft.com/en-ca/magazine/cc163715.aspx#S5</description></item></list></summary>
    <remarks>To be added.</remarks>
    <example>
            Bad example:
            <code>
            public class Singleton {
            	private static Singleton instance;
            	private static object syncRoot = new object ();
            	public static Singleton Instance {
            		get {
            			if (instance == null) {
            				lock (syncRoot) {
            					if (instance == null) {
            						instance = new Singleton ();
            					}
            				}
            			}
            			return instance;
            		}
            	}
            }
            </code></example>
    <example>
            Good example (for 1.x code avoid using double check):
            <code>
            public class Singleton {
            	private static Singleton instance;
            	private static object syncRoot = new object ();
            	public static Singleton Instance {
            		get {
            			// do not check instance before the lock
            			// this will work on all CLRs but will affect
            			// performance since the lock is always acquired
            			lock (syncRoot) {
            				if (instance == null) {
            					instance = new Singleton ();
            				}
            			}
            			return instance;
            		}
            	}
            }
            </code></example>
    <example>
            Good example (for 2.x and later):
            <code>
            public class Singleton {
            	// by using 'volatile' the double check will work under CLR 2.x
            	private static volatile Singleton instance;
            	private static object syncRoot = new object ();
            	public static Singleton Instance {
            		get {
            			if (instance == null) {
            				lock (syncRoot) {
            					if (instance == null) {
            						instance = new Singleton ();
            					}
            				}
            			}
            			return instance;
            		}
            	}
            }
            </code></example>
  </Docs>
  <Members>
    <Member MemberName=".ctor">
      <MemberSignature Language="C#" Value="public DoubleCheckLockingRule ();" />
      <MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor() cil managed" />
      <MemberType>Constructor</MemberType>
      <AssemblyInfo>
        <AssemblyVersion>2.11.0.0</AssemblyVersion>
      </AssemblyInfo>
      <Parameters />
      <Docs>
        <summary>To be added.</summary>
        <remarks>To be added.</remarks>
      </Docs>
    </Member>
    <Member MemberName="CheckMethod">
      <MemberSignature Language="C#" Value="public Gendarme.Framework.RuleResult CheckMethod (Mono.Cecil.MethodDefinition method);" />
      <MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance valuetype Gendarme.Framework.RuleResult CheckMethod(class Mono.Cecil.MethodDefinition method) cil managed" />
      <MemberType>Method</MemberType>
      <AssemblyInfo>
        <AssemblyVersion>2.11.0.0</AssemblyVersion>
      </AssemblyInfo>
      <ReturnValue>
        <ReturnType>Gendarme.Framework.RuleResult</ReturnType>
      </ReturnValue>
      <Parameters>
        <Parameter Name="method" Type="Mono.Cecil.MethodDefinition" />
      </Parameters>
      <Docs>
        <param name="method">To be added.</param>
        <summary>To be added.</summary>
        <returns>To be added.</returns>
        <remarks>To be added.</remarks>
      </Docs>
    </Member>
    <Member MemberName="Initialize">
      <MemberSignature Language="C#" Value="public override void Initialize (Gendarme.Framework.IRunner runner);" />
      <MemberSignature Language="ILAsm" Value=".method public hidebysig virtual instance void Initialize(class Gendarme.Framework.IRunner runner) cil managed" />
      <MemberType>Method</MemberType>
      <AssemblyInfo>
        <AssemblyVersion>2.11.0.0</AssemblyVersion>
      </AssemblyInfo>
      <ReturnValue>
        <ReturnType>System.Void</ReturnType>
      </ReturnValue>
      <Parameters>
        <Parameter Name="runner" Type="Gendarme.Framework.IRunner" />
      </Parameters>
      <Docs>
        <param name="runner">To be added.</param>
        <summary>To be added.</summary>
        <remarks>To be added.</remarks>
      </Docs>
    </Member>
  </Members>
</Type>
