Boost logo

Boost Users :

Subject: Re: [Boost-users] Using Boost Mutex
From: Wesley Bland (wesbland_at_[hidden])
Date: 2009-09-18 14:52:43


That seems to have solved the problem. Thanks very much.

On Fri, Sep 18, 2009 at 2:16 PM, Neil Groves <neil_at_[hidden]>wrote:

>
>
> On Fri, Sep 18, 2009 at 6:21 PM, Wesley Bland <wesbland_at_[hidden]> wrote:
>
>> This is firmly in n00b territory.
>> I'm trying to use a boost::mutex to lock a STL queue. The mutex is stored
>> in a class in a map. When I pass the mutex to the boost::mutex::scoped_lock
>> constructor, I get this error:
>>
>> /usr/local/include/boost/noncopyable.hpp: In copy constructor
>> ‘boost::mutex::mutex(const boost::mutex&)’:
>> /usr/local/include/boost/thread/pthread/mutex.hpp:31: instantiated from
>> ‘_Tp& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const _Key&) [with
>> _Key = int, _Tp = boost::mutex, _Compare = std::less<int>, _Alloc =
>> std::allocator<std::pair<const int, boost::mutex> >]’
>> SwitchBox.cpp:15: instantiated from here
>> /usr/local/include/boost/noncopyable.hpp:27: error:
>> ‘boost::noncopyable_::noncopyable::noncopyable(const
>> boost::noncopyable_::noncopyable&)’ is private
>> /usr/local/include/boost/thread/pthread/mutex.hpp:31: error: within this
>> context
>> /usr/include/c++/4.2.1/bits/stl_map.h: In member function ‘_Tp&
>> std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const _Key&) [with _Key =
>> int, _Tp = boost::mutex, _Compare = std::less<int>, _Alloc =
>> std::allocator<std::pair<const int, boost::mutex> >]’:
>> /usr/include/c++/4.2.1/bits/stl_map.h:350: note: synthesized method
>> ‘boost::mutex::mutex(const boost::mutex&)’ first required here
>>
>> This appears to be complaining about me passing the mutex into the
>> scoped_lock. Can anyone give me some help here? I've included a much
>> shortened version of the code that otherwise compiles.
>>
>>
> It's complaining about the mutex being in a map. The map requires the
> elements within it to be copy constructable which boost::mutex isn't by
> design. You might want to consider using a shared_ptr<mutex>.
>
>
>> Thanks for your help,
>> Wesley
>>
>> <snip code />
>
> Regards,
> Neil Groves
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>

-- 
===========================
Wesley Bland
Graduate Research Assistant
ICL / EECS Department
University of Tennessee
wbland_at_[hidden]
(865) 896-9371


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net