title: Difference between using a mutex locker and locking the mutex manually
body: <p>Specifically, in a const member function if I use <code>mutex.lock()</code> at the beginning of it, and <code>mutex.unlock()</code> right before the return, I get crashes when running it inside an OpenMP loop. But if I replace those two calls with one <code>QMutexLocker(&amp;mutex)</code> at the beginning of the function, it runs smoothly.
  Visual Studio 2010, Qt 4.8.
  I would expect the two codes to be equivalent, but they are obviously not. What am I missing here?</p>
  
  <p>EDIT:
  Although this doesn't reproduce the problem, a small example:</p>
  
  <pre><code>class TileCache
  {
  public:
      bool fillBuffer(const std::string&amp; name) const {
          //QMutexLocker lock(&amp;mCacheMutex);
          mCacheMutex.lock();
          auto ite = mCache.find(name);
          if(ite == mCache.end())
              mCache.insert(ite, std::make_pair(name, new unsigned char[1024]));
          // code here
          mCacheMutex.unlock();
          return true;
      }
  private:
      mutable std::map&lt;std::string, unsigned char*&gt; mCache;
      mutable QMutex mCacheMutex;
  };
  
  int main(int argc, char *argv[])
  {
      std::cout &lt;&lt; "Test" &lt;&lt; std::endl;
      TileCache cache;
  #pragma omp parallel for shared(cache)
      for(int i = 0; i &lt; 2048; ++i)
      {
          cache.fillBuffer("my buffer");
      }
      return 0;
  }
  </code></pre>
  
  <p>I was basically asking if there is any known reason to believe that the two ways are not equivalent, if always calling <code>lock()</code>/<code>unlock()</code> (no <code>lock()</code> call without its matching <code>unlock()</code>) can behave differently than <code>QMutexLocker</code>, under some circumstances.</p>