From 0bcdbbe6822cae556927f9ae7a7d391214732c62 Mon Sep 17 00:00:00 2001 From: Arnaud Gody Date: Mon, 18 Sep 2017 11:51:59 -0400 Subject: [PATCH] Fix sharable counter wraparound when unlock_sharable function is called and counter is already equal to 0 --- .../sync/interprocess_sharable_mutex.hpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/include/boost/interprocess/sync/interprocess_sharable_mutex.hpp b/include/boost/interprocess/sync/interprocess_sharable_mutex.hpp index 59823b0..57713c5 100644 --- a/include/boost/interprocess/sync/interprocess_sharable_mutex.hpp +++ b/include/boost/interprocess/sync/interprocess_sharable_mutex.hpp @@ -327,15 +327,19 @@ inline bool interprocess_sharable_mutex::timed_lock_sharable inline void interprocess_sharable_mutex::unlock_sharable() { scoped_lock_t lck(m_mut); - //Decrement sharable count - --this->m_ctrl.num_shared; - if (this->m_ctrl.num_shared == 0){ - this->m_second_gate.notify_one(); - } - //Check if there are blocked sharables because of - //there were too many sharables - else if(this->m_ctrl.num_shared == (constants::max_readers-1)){ - this->m_first_gate.notify_all(); + + if(this->m_ctrl.num_shared != 0){ + //Decrement sharable count + --this->m_ctrl.num_shared; + + if(this->m_ctrl.num_shared == 0){ + this->m_second_gate.notify_one(); + } + //Check if there are blocked sharables because of + //there were too many sharables + else if(this->m_ctrl.num_shared == (constants::max_readers-1)){ + this->m_first_gate.notify_all(); + } } } -- 2.14.1.windows.1