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

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #9569: Upgrade lock is not acquired when previous upgrade lock releases if another read lock is present
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-02-26 07:10:08


#9569: Upgrade lock is not acquired when previous upgrade lock releases if another
read lock is present
--------------------------------------------+------------------------------
  Reporter: Rodionov Andrew <camelot58@…> | Owner: viboes
      Type: Bugs | Status: assigned
 Milestone: To Be Determined | Component: thread
   Version: Boost 1.55.0 | Severity: Problem
Resolution: | Keywords: shared_mutex
                                            | windows
--------------------------------------------+------------------------------

Comment (by viboes):

 Hi,

 Please could you try adding

 {{{

         void release_shared_waiters(state_data old_state)
         {

             if(old_state.shared_waiting || old_state.exclusive_waiting)
             {
 BOOST_VERIFY(detail::win32::ReleaseSemaphore(semaphores[unlock_sem],old_state.shared_waiting
 + (old_state.exclusive_waiting?1:0),0)!=0);
             }
         }

 }}}

 and changing the implementation to

 {{{



         void unlock_upgrade()
         {
             state_data old_state=state;
             for(;;)
             {
                 state_data new_state=old_state;
                 new_state.upgrade=false;
                 bool const last_reader=!--new_state.shared_count;

                 if(last_reader)
                 {
                     if(new_state.exclusive_waiting)
                     {
                         --new_state.exclusive_waiting;
                         new_state.exclusive_waiting_blocked=false;
                     }
                     new_state.shared_waiting=0;
                 }

                 state_data const
 current_state=interlocked_compare_exchange(&state,new_state,old_state);
                 if(current_state==old_state)
                 {
                     if(last_reader)
                     {
                         release_waiters(old_state);
                     }
                     else {
                         release_shared_waiters(old_state);
                     }
                     // #7720
                     //else {
                     // release_waiters(old_state);
                     //}
                     break;
                 }
                 old_state=current_state;
             }
         }
 }}}

 Please could you also try the test in #7720?

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/9569#comment:2>
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:15 UTC