title: Best C# solution for multithreaded threadsafe read/write locking?
body: <p>What is the safest (and shortest) way do lock read/write access to <code>static</code> members in a multithreaded environment in C#? </p>
  
  <p>Is it possible to do the threadsafe locking &amp; unlocking on class level (so I don't keep repeating lock/unlock code every time static member access is needed)?</p>
  
  <p><strong>Edit</strong>: Sample code would be great :)</p>
  
  <p><strong>Edit</strong>: Should I use the <strong>volatile</strong> keyword or <strong>Thread.MemoryBarrier()</strong> to avoid multiprocessor caching or is that unnecessary? According to Jon Skeet only those will make changes visible to other processors? (Asked this separately <a href="https://stackoverflow.com/questions/1330590/when-to-use-volatile-or-thread-memorybarrier-in-threadsafe-locking-code-c">here</a>).</p>