Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The decision to leave shared_mutex was made independently of any quality issues. The decision was part of the "Kona compromise" made in the Fall of 2007. This compromise was aimed at reducing the feature set of C++0x so as to ship a standard by 2009. It didn't work, but nevertheless, that is the rationale.</p> <p>shared_mutex's will be discussed for inclusion to a technical report (i.e. tr2) after the committee has completed C++0x. The chairman on the library working group has already contacted me on this very subject. That is not to say that shared_mutex will be in tr2. Just that it will be discussed.</p> <p>Your implementation of AquireReadLock and AquireWriteLock have the disadvantage in that they eat a stack frame at the rate of once per second when under contention. And when contention is over, they delay up to a second before reacting. This makes them both stack hungry and poor performing (sorry).</p> <p>If you are interested, there is a full description and implementation of shared_mutex here:</p> <p><a href="http://home.roadrunner.com/~hinnant/mutexes/locking.html" rel="noreferrer">http://home.roadrunner.com/~hinnant/mutexes/locking.html</a></p> <p>The code is not part of boost, but does carry the boost open source license. Feel free to use it, just keep the copyright with the source code. No other strings attached. Here is its analog to your AquireReadLock:</p> <pre><code>void shared_mutex::lock_shared() { std::unique_lock&lt;mutex_t&gt; lk(mut_); while ((state_ &amp; write_entered_) || (state_ &amp; n_readers_) == n_readers_) gate1_.wait(lk); count_t num_readers = (state_ &amp; n_readers_) + 1; state_ &amp;= ~n_readers_; state_ |= num_readers; } </code></pre> <p>And here is its analog to your AquireWriteLock:</p> <pre><code>void shared_mutex::lock() { std::unique_lock&lt;mutex_t&gt; lk(mut_); while (state_ &amp; write_entered_) gate1_.wait(lk); state_ |= write_entered_; while (state_ &amp; n_readers_) gate2_.wait(lk); } </code></pre> <p>I consider this a well-tested and high-performing, fair read/write mutex implementation for C++. If you have ideas on how to improve it, I would welcome them.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload