title: Lock in Framework 3.5 vs 4.0?
body: <p><a href="http://msdn.microsoft.com/en-us/library/vstudio/dd289498%28v=vs.100%29.aspx" rel="nofollow">AFAIK</a> , there is a difference between <code>lock</code> in those 2 versions.</p>
  
  <p>Framework 4 added one more check if there was an exception during monitor enter ( like out of memory  exception) </p>
  
  <p>And there is a <code>lockTaken</code> flag which indicates if a lock should be released (in a <code>finally</code> clause) or not ( due to fail code in a <code>try</code> clause).</p>
  
  <p>Something  like </p>
  
  <pre><code>bool lockTaken = false;
  try
  {
     Monitor.Enter (lockObj, ref lockTaken);
     ...
  }
  finally { if (lockTaken) Monitor.Exit (lockObj); }
  </code></pre>
  
  <p>(very much similar to the <code>using</code> code (dispose...))</p>
  
  <p><strong>But</strong> viewing by relfector I see totally different thing : </p>
  
  <pre><code>[SecuritySafeCritical]
  public static void Enter(object obj, ref bool lockTaken)
  {
      if (lockTaken)
      {
          throw new ArgumentException(Environment.GetResourceString("Argument_MustBeFalse"), "lockTaken");
      }
      ReliableEnter(obj, ref lockTaken);
  }
  </code></pre>
  
  <p><em>where is the pattern of try , finally ?</em> </p>
  
  <p>What am I missing ? </p>