title: Automatic locking/unlocking using scope in C++ (from C# background)
body: <p>I've been using C# for the last few years and I am currently bug fixing in C++.
  In C# I could use lock on an object to make my code thread safe with:</p>
  
  <pre><code>lock(lockObject)
  {
      // Do some work
  }
  </code></pre>
  
  <p>This would unlock the lockOject if there was an exception within the <code>// Do some work</code></p>
  
  <p>Is there something similar in C++? At the moment I can think of either:</p>
  
  <pre><code>// Code
  {
      AutoLock lock(lockObject);
      // Do some work
  }
  // More Code
  </code></pre>
  
  <p>But I don't like the curly braces just to scope my <code>AutoLock</code>. At the moment I'm doing:</p>
  
  <pre><code>AutoLock lock(lockObject);
  // Do some work
  lock.Unlock();
  </code></pre>
  
  <p>And letting exception unwinding release the lock if there's an exception in <code>//Do some work</code>.</p>
  
  <p>What I'm doing at the moment works, but I'm wondering if there's a better way, thanks.</p>