title: Can a shared lock on a std::shared_timed_mutex be upgraded to an exclusive lock?
body: <p>The new std::shared_timed_mutex allows for two types of locks: shared and exclusive.</p>
  
  <p>If one holds a shared lock, is there any way to atomically exchange it ("upgrade it") to an exclusive lock? In other words, given the following code, how can I avoid the non-atomic drop and re-lock?</p>
  
  <pre><code>std::shared_timed_mutex m; //Guards a std::vector.
  m.lock_shared();
  
  //Read from vector. (Shared lock is sufficient.)
  // ...
  
  //Now we want to write to the vector. We need an exclusive lock.
  m.unlock_shared();
                     //     &lt;---- Problem here: non-atomic! 
  m.lock(); 
  
  //Write to vector.
  // ...
  
  m.unlock();
  </code></pre>
  
  <p>Ideally, <code>m.unlock_shared(); m.lock();</code> could be replaced with something like <code>m.upgrade_to_exclusive();</code> (or something like the <code>boost::.upgrade_to_unique_lock()</code>).</p>
  
  <p><a href="https://stackoverflow.com/questions/7378266/upgrading-boostshared-lock-to-exclusive-lock">In a similar question but for Boost's shared_mutex</a> Dave S mentions </p>
  
  <blockquote>
    <p>It is impossible to convert from a shared lock to a unique lock, or a shared lock to an upgradeable lock without releasing the shared lock first.</p>
  </blockquote>
  
  <p>I'm not certain whether this applies to std::shared_mutex, though I suspect it does.</p>
  
  <p>I would be happy with a reasonable work-around based on std::atomic/condition_variable or GCC's transactional memory.</p>
  
  <p><strong>Edit:</strong> Howard's answer addresses my question. His <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3427.html" rel="noreferrer">proposal N3427</a> contains nice descriptions of a mechanism to achieve mutex upgrading. I still welcome work-arounds based on std::atomic/condition_variable or GCC's transactional memory.</p>