Boost logo

Threads-Devel :

Subject: Re: [Threads-devel] v2/shared_mutex bitmask refactoring
From: Fredrik Orderud (forderud_at_[hidden])
Date: 2013-03-26 14:09:58


On Tue, Mar 26, 2013 at 5:57 AM, Vicente J. Botet Escriba <
vicente.botet_at_[hidden]> 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



Threads-Devel list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk