Subject: [Boost-bugs] [Boost C++ Libraries] #1951: boost::interprocess::named_condition::do_wait() releases mutex prematurely, may miss notification
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-05-26 21:27:32
#1951: boost::interprocess::named_condition::do_wait() releases mutex prematurely,
may miss notification
---------------------------------------------------------------------------------+
Reporter: Stas Maximov <smaximov_at_[hidden]> | Owner: igaztanaga
Type: Bugs | Status: new
Milestone: Boost 1.36.0 | Component: interprocess
Version: Boost 1.35.0 | Severity: Showstopper
Keywords: named_condition_variable interprocess sync mutex condition_variable |
---------------------------------------------------------------------------------+
Implementation of boost::interprocess::named_condition::do_wait() is shown
below:
template <class Lock>
void do_wait(Lock& lock)
{
lock_inverter<Lock> inverted_lock(lock);
//unlock internal first to avoid deadlock with near simultaneous waits
scoped_lock<lock_inverter<Lock> > external_unlock(inverted_lock);
scoped_lock<interprocess_mutex> internal_lock(*this->mutex());
this->condition()->wait(internal_lock);
}
Lock lock is associated with the condition variable and must be released
only inside wait(). This implementation releases the lock before it enters
the wait(). If lock released before wait() is entered, this function may
be pre-empted by a notifier thread, just after the lock has been released,
but before wait() has been entered. In such case notification will be
missed by the wait().
Having a mutex associated with condition variable is a fundamental
requirement. Use of another mutex (internal_lock in this case), not known
to the notifier is not a solution. Both the receiver and the notifier,
both must use the same CV *and* MX.
This is like a root cause of hangs in named_condition_test on Fedora9
running on single-cpu system under vmware-server-1.0.5.
--
Ticket URL: <http://svn.boost.org/trac/boost/ticket/1951>
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:49:57 UTC