Re: [Boost-bugs] [Boost C++ Libraries] #5516: Upgrade lock is not acquired when previous upgrade lock releases if another read lock is present

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #5516: Upgrade lock is not acquired when previous upgrade lock releases if another read lock is present
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-12-29 11:37:28


#5516: Upgrade lock is not acquired when previous upgrade lock releases if another
read lock is present
------------------------------------+---------------------------------------
  Reporter: fred@… | Owner: viboes
      Type: Bugs | Status: assigned
 Milestone: To Be Determined | Component: thread
   Version: Boost 1.42.0 | Severity: Problem
Resolution: | Keywords:
------------------------------------+---------------------------------------
Changes (by viboes):

  * type: Support Requests => Bugs

Comment:

 Replying to [comment:7 fred@…]:
> Viboes, agreed, last steps don't matter. My concern here is on the 7th
 step:
>
> m1 - Trying to take an shared lock[[BR]]
> m1 - Took a shared lock[[BR]]
> m2 - Trying to take an upgradable lock[[BR]]
> m2 - Took an upgradable lock[[BR]]
> m3 - Trying to take an upgradable lock[[BR]]
> m2 - Released an upgradable lock[[BR]]
> ** here I would expect m3 to be able to take the upgradable lock, even
 though m1 still has a read lock **[[BR]]
>
> m1 - Released the lock
>
> Because the "release_waiters()" is only called when there are no more
 readers, we ignore the case when a thread wanting an upgradable lock
 should be waken up when there are still read locks going on.
>
> This makes the locking non-eager.


 You are right. The fact that in


 {{{
         void unlock_upgrade()
         {
             boost::mutex::scoped_lock lk(state_change);
             state.upgrade=false;
             bool const last_reader=!--state.shared_count;

             if(last_reader)
             {
                 state.exclusive_waiting_blocked=false;
                 release_waiters();
             }
         }
 }}}

 state.upgrade has been set at least


 {{{
 shared_cond.notify_all();
 }}}


 must be called.

 Please could you try the following


 {{{
         void unlock_upgrade()
         {
             boost::mutex::scoped_lock lk(state_change);
             state.upgrade=false;
             bool const last_reader=!--state.shared_count;

             if(last_reader)
             {
                 state.exclusive_waiting_blocked=false;
                 release_waiters();
             } else {
               shared_cond.notify_all();
             }
         }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/5516#comment:8>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:08 UTC