title: Using QMutex::tryLock and QMutexLocker
body: <p>I have a background function that currently has something like follows:</p>
  
  <pre><code>void SomeClass::someFunction()
  {
      if (!_mutex.tryLock())
      {
          // i want to know the mutex is locked, and then exit the function
          return;
      }
      else
      {
          _mutex.unlock();
      }
  
      QMutexLocker locker(_mutext);
  
      // do some stuff that **could** throw an exception
  }
  </code></pre>
  
  <p>My dilemma concerns the <code>_mutex.unlock()</code> and <code>QMutextLocker</code> statement. </p>
  
  <p>If the <code>_mutex</code> is locked, then I want to know about it. If it's not, then I want lock it. The problem is that I want to use <code>QMutexLocker</code> to lock <code>_mutex</code> for the bulk of the function. It's possible that the function could throw an exception, so manually unlocking <code>_mutex</code> could be difficult and error prone. </p>
  
  <p>The above solution works but what concerns me is that sometime between the <code>_mutex.unlock()</code> and the deceleration of <code>QMutexLocker</code> something else could come along and lock the mutex.</p>
  
  <p>Does anyone have any suggestions of a better way to do this?</p>
  
  <p>Thank you.</p>