What all should I know about std::unique_lock?
<p>From what I have understood, <code>std::unique_lock</code> is a kind of wrapper around the underlying <code>mutex</code> object so as to provide a <em>safer</em> implementation over using raw <code>mutex</code>es (e.g., end up in unlocked state if an exception is thrown or on destruction). Is this all <code>std::unique_lock</code> is for?</p>

<p>Try #1</p>

<pre><code>std::mutex m;  // global 
void foo() {
  m.lock();
  // critical section
  m.unlock();
}
</code></pre>

<p>Try #2</p>

<pre><code>std::mutex m;  // global 
void foo() {
  std::unique_lock&lt;std::mutex&gt; ul(m);
  // critical section
}
</code></pre>

<p>Is Try #2 preferred over Try #1, and is this what <code>std::unique_lock</code> is for? Please provide some other examples where <code>std::unique_lock</code> may be desired.</p>