On Tue, Mar 26, 2013 at 5:57 AM, Vicente J. Botet Escriba <vicente.botet@wanadoo.fr> wrote:
BTW,
do you understand why there is a test in (*)?

    void
    upgrade_mutex::unlock_shared()
    {
      boost::lock_guard<mutex_t> _(mut_);
      count_t num_readers = (state_ & n_readers_) - 1;
      state_ &= ~n_readers_;
      state_ |= num_readers;
      if (state_ & write_entered_)
      {
        if (num_readers == 0)
          gate2_.notify_one();
      }
      else
      {
        if (num_readers == n_readers_ - 1) // (*)
          gate1_.notify_one();
      }
    }

Assuming that gate1_ controls read-locks, then the check at (*) appears to revive any waiting lock_shared attempts that have previously been blocked due to the limit of maximum (2^31-1) simultaneous read-locks.

Unless I misunderstand something, then this appears to be an extremely unlikely situation. Neither pthread/shared_mutex nor win32/shared_mutex have any similar protection against reaching the maximum limit of simultaneous read-locks.

Fredrik