title: Is there anything Faster than a boost mutex for this code?
body: <p>Currently in my code I have sections such as this</p>
  
  <pre><code>boost::mutex Mymutex
  
  void methodA()
  {
     boost::mutex::scoped_lock lock(Mymutex);
     ......
     ......
     ......
  }
  </code></pre>
  
  <p>I read that critical sections are faster than a mutex ? So I am doing something like this I wanted to know if this is faster.</p>
  
  <pre><code> boost::recursive_mutex m_guard;
   void methodA()
   {
         // this section is not locked
        {
            boost::lock_guard&lt;boost::recursive_mutex&gt; lock(m_guard);
           // this section is locked
        }
        //This section not locked
   }    
  </code></pre>
  
  <p>Is the second method faster ? The reason I am mostly using mutex is to prevent race conditions and lock access to methods so that one thread accesses it at a time. Is there anything faster than that ? My other concern was on the statement</p>
  
  <pre><code>  boost::lock_guard&lt;boost::recursive_mutex&gt; lock(m_guard);
  </code></pre>
  
  <p>it seems that everytime methodA() would be called lock would be created on the stack.
  I was thinking about declaring lock as a static variable so it does not get created on the stack everytime this method is called.In that case how can I add m_guard to it. For instance</p>
  
  <pre><code> boost::recursive_mutex SomeClass::m_guard; //This is static 
   boost::lock_guard&lt;boost::recursive_mutex&gt; SomeClass::lock //Suppose this is static
   void SomeClass::methodA()
   {
  
        {
           //How do i make lock "lock" mguard 
  
        }
  
   }    
  </code></pre>