title: Best Practices in using a lock
body: <p>Suppose I have the following property in some class, and its purpose is to be used as a lock. </p>
  
  <pre><code>protected object SyncRoot { get; private set; }
  </code></pre>
  
  <p>Anyways, regardless of how and if this was set. What is best practice to go about using it if it is, in fact, set?</p>
  
  <p>Since lock does not work with null objects, should I handle it like this?</p>
  
  <pre><code>lock (SyncRoot ?? new object())
      SomeMethod();
  </code></pre>
  
  <p>Or should I check for null like this?</p>
  
  <pre><code>if (SyncRoot != null)
      lock (SyncRoot)
          SomeMethod();
  else
      SomeMethod();
  </code></pre>
  
  <p>If it is, in fact, set, I'd want to use it to lock. Otherwise, I don't care. Is the first solution inefficient or redundant in anyway?</p>
  
  <p>EDIT: All these answers are good. However, I can only pick one. Given my situation as discussed with Luke, there is no reason why my SyncRoot should be null. The overhead of a lock in a single threaded environment is no biggy, but necessary if in a multi-threaded one. </p>
  
  <p>(Vote ups for all 4 of ya) Thank you all for your speedy replies.</p>