title: Ensuring that current thread holds a lock on a C++11 mutex
body: <p>Is there a way to tell whether or not the current thread in C++11 holds a lock on a mutex?  In particular I want to ensure that certain functions in a class are only called while the calling thread holds onto a lock (via <code>std::lock_guard</code>, <code>std::unique_lock</code>, or something similar) for the object, with the <code>std::mutex</code> being a member variable.</p>
  
  <p>To avoid repeated locking and unlocking while the object is being used extensively, the responsibility for locking the <code>mutex</code> needs to be up to the caller, and cannot be in each individual function, and if the current thread does not have a lock on the <code>mutex</code> when any of these functions are called, I want to throw an exception.</p>
  
  <p>It seems that I can't just use <code>std::try_lock</code> followed by an unlock as necessary because <code>std::try_lock</code>'s behavior is undefined if the current thread already holds the lock.</p>