Opened 13 years ago

Closed 13 years ago

#3354 closed Bugs (fixed)

regex's static_mutex.cpp passes "false" to scoped_lock's constructor

Reported by: mdorey@… Owned by: John Maddock
Milestone: Boost 1.40.0 Component: regex
Version: Boost 1.39.0 Severity: Problem
Keywords: Cc:

Description

This line in libs/regex/src/static_mutex.cpp's scoped_static_mutex_lock::lock() method passes a bool as a second argument to scoped_lock's constructor:

m_plock = new boost::recursive_mutex::scoped_lock(*static_mutex::m_pmutex, false);

This only happens on non-pthread systems which don't support WINTHREADS, so perhaps this is minority-interest code, which perhaps explains why it hasn't been noticed before.

On the particular platform I'm using, scoped_lock is defined as unique_lock of a mutex type which doesn't support timed-waits. unique_lock has an undocumented constructor which gcc has determined as the best match:

template<typename TimeDuration> unique_lock(Mutex& m_,TimeDuration const& target_time):

Clearly, the intention of this code wasn't to wait on the lock for up to zero TimeDuration units. Other code in the same file leads me to think that the bool is intended to tell scoped_lock to defer taking out the lock. The line following the line in question then takes out the lock:

if(0 == m_plock)

m_plock = new boost::recursive_mutex::scoped_lock(*static_mutex::m_pmutex, false);

m_plock->lock(); m_have_lock = true;

Earlier in the file, there's a similar bool which is definitely used this way:

scoped_static_mutex_lock::scoped_static_mutex_lock(static_mutex& , bool lk) : m_plock(0), m_have_lock(false) {

if(lk)

lock();

}

I'm new to boost's thread library, so slap me if I'm wrong, but I'm a-thinkin' that the modern way to do this with boost::defer_lock. And je vous presente un patch in that vein.

Attachments (1)

static_mutex.cpp.patch (568 bytes ) - added by mdorey@… 13 years ago.
s/false/boost::defer_lock/

Download all attachments as: .zip

Change History (2)

by mdorey@…, 13 years ago

Attachment: static_mutex.cpp.patch added

s/false/boost::defer_lock/

comment:1 by John Maddock, 13 years ago

Resolution: fixed
Status: newclosed

(In [55683]) Apply patch from issue #3354. Fixes #3354.

Note: See TracTickets for help on using tickets.