title: how does the lock() function work in c#?
body: <p>I have some c# code which looks like this:</p>
  
  <pre><code>if (cache[filename] != null) {
      return (AppSettings)cache[filename];
  }
  
  lock (thisLock)
  {
      using (StreamReader sr = new StreamReader(filename))
      {
          instance = (AppSettings)serial.Deserialize(sr);
          cache.Insert(filename, instance, null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration);
      }
  
  }
  
  return (AppSettings)cache[filename];
  </code></pre>
  
  <p>so, my understanding of a lock, is that once it has become "Unlocked", then the code block will be executes. So in the case of the code above, I'm assuming I'll need another check in the lock code block to see if the object has already been created?</p>
  
  <p>Also how would I check for a deadlock?</p>