title: how to make sure locker be unlock in c++? which solution is better
body: <p>there are two solutions:</p>
  
  <p>A:</p>
  
  <pre><code>lock()
  try{
      action()
  }catch(...)
  {
      unlock()
      throw;
  }
  unlock()
  </code></pre>
  
  <p>B:</p>
  
  <pre><code>{
  LockObject lockObject;
  action();
  }
  </code></pre>
  
  <p>LockObject's constuctor will call lock(),its de-construtor will call unlock().</p>
  
  <p>So what's the better solution or is there any other better solution?</p>
  
  <p>ps: in linux c++, it doesn't support keywords finally. So I have to make decision for this issue.</p>