Using the boost :: scoped_lock constructor (Mutex & mx, bool initial_locked) gives me errors

Is there a boost :: scoped_lock constructor that takes a boolean as the second parameter? I thought I used it before. boost :: scoped_lock (Mutex & mx, bool initial_locked)

The documentation for scoped_lock shows that the second parameter is "unspecified." Does anyone know what in @ (* $, which, suppose, means?!?

I get the following errors:

c:\program files\boost\boost_1_39\boost\thread\win32\basic_timed_mutex.hpp(118) : error C2679: binary '+' : no operator found which takes a right-hand operand of type 'const bool' (or there is no acceptable conversion)
        c:\program files\boost\boost_1_39\boost\date_time\posix_time\date_duration_operators.hpp(31): could be 'boost::posix_time::ptime boost::posix_time::operator +(const boost::posix_time::ptime &,const boost::gregorian::months &)' [found using argument-dependent lookup]
        c:\program files\boost\boost_1_39\boost\date_time\date_duration_types.hpp(132): or       'boost::gregorian::date boost::date_time::months_duration<base_config>::operator +(const boost::gregorian::date &,const boost::date_time::months_duration<base_config> &)' [found using argument-dependent lookup]
        with
        [
            base_config=boost::gregorian::greg_durations_config
        ]
        c:\program files\boost\boost_1_39\boost\date_time\posix_time\date_duration_operators.hpp(75): or       'boost::posix_time::ptime boost::posix_time::operator +(const boost::posix_time::ptime &,const boost::gregorian::years &)' [found using argument-dependent lookup]
        c:\program files\boost\boost_1_39\boost\date_time\date_duration_types.hpp(244): or       'boost::gregorian::date boost::date_time::years_duration<base_config>::operator +(const boost::gregorian::date &,const boost::date_time::years_duration<base_config> &)' [found using argument-dependent lookup]
        with
        [
            base_config=boost::gregorian::greg_durations_config
        ]
        c:\program files\boost\boost_1_39\boost\date_time\time.hpp(139): or       'boost::posix_time::ptime boost::date_time::base_time<T,time_system>::operator +(const boost::gregorian::date_duration &) const'
        with
        [
            T=boost::posix_time::ptime,
            time_system=boost::posix_time::posix_time_system
        ]
        c:\program files\boost\boost_1_39\boost\date_time\time.hpp(159): or       'boost::posix_time::ptime boost::date_time::base_time<T,time_system>::operator +(const boost::posix_time::time_duration &) const'
        with
        [
            T=boost::posix_time::ptime,
            time_system=boost::posix_time::posix_time_system
        ]
        while trying to match the argument list '(boost::system_time, const bool)'
        c:\program files\boost\boost_1_39\boost\thread\locks.hpp(353) : see reference to function template instantiation 'bool boost::detail::basic_timed_mutex::timed_lock<TimeDuration>(const Duration &)' being compiled
        with
        [
            TimeDuration=bool,
            Duration=bool
        ]
        c:\program files\boost\boost_1_39\boost\thread\locks.hpp(241) : see reference to function template instantiation 'bool boost::unique_lock<Mutex>::timed_lock<TimeDuration>(const TimeDuration &)' being compiled
        with
        [
            Mutex=boost::mutex,
            TimeDuration=bool
        ]
        d:\imagehawk\projects\virtualpc_archiveservice\ifl\src\archiveservice\archive.cpp(599) : see reference to function template instantiation 'boost::unique_lock<Mutex>::unique_lock<bool>(Mutex &,const TimeDuration &)' being compiled
        with
        [
            Mutex=boost::mutex,
            TimeDuration=bool
        ]

Here is some of my source code if this helps:

void SpawnXMessageThread(bool bTakeLock=true) {
    boost::mutex::scoped_lock lock(m_mtx,bTakeLock);
    m_pxmessage= new XMessage();
    m_pThread = new boost::thread(boost::ref(*m_pxmessage));
}

The idea is that I will block m_mtx based on a logical one. That way, if I block m_mtx before calling SpawnXMessageThread, I can tell SpawnXMessageThread not to block the mutexes (because I blocked it).

btw, boost .

+3
1

, . - :

boost::unique_lock lck(m_mtx, boost::defer_lock);
if(bTakeLock) lck.lock();
+3

Source: https://habr.com/ru/post/1737058/


All Articles