title: How to handle a pthread_mutex_unlock() error?
body: <p>I'm developing a thread-safe class that also handle errors. I was wonder how to handle a possible error that come from the function pthread_mutex_unlock(). If I throw the mutex is still locked? Should I try to unlock it again or destroy the class object?</p>
  
  <pre><code>int SomeClass::function() {   
      int res = pthread_mutex_lock(&amp;_mutex);
      if(res &lt; 0)
          throw std::runtime_error("lock failed: " + std::string(std::strerror(res)));
      // some code
      res = pthread_mutex_unlock(&amp;_mutex);
      if(res &lt; 0)
          throw std::runtime_error("unlock failed: " + std::string(std::strerror(res)));
      return something;
  }
  </code></pre>
  
  <p>Thanks!</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>the vaiable <code>_mutex</code> is a protected class member (non static) initialized inside the constructor using only <code>pthread_mutex_init(&amp;_mutex, NULL)</code></p>