我在向此类中添加复制构造函数时遇到问题:
http://www.justsoftwaresolutions.co.uk/threading/implementing-a-thread-safe-queue-using-condition-variables.html
我需要添加它,以便可以在stl向量容器中添加并发队列。
concurrent_queue(concurrent_queue<Data> const& rhs):
the_queue(rhs.the_queue),
the_mutex(rhs.the_mutex),
the_condition_variable(rhs.the_condition_variable)
{
}
concurrent_queue<Data>& operator = (concurrent_queue<Data> const& rhs)
{
if (this == &rhs) return *this; // check for self assignment
the_queue = rhs.the_queue;
the_mutex(rhs.the_mutex);
the_condition_variable(rhs.the_condition_variable);
}
我得到的错误如下:
concurrentqueue.h: In copy constructor âconcurrent_queue<Data>::concurrent_queue(const concurrent_queue<Data>&) [with Data = Packet*]â:
/usr/include/c++/4.4/bits/stl_construct.h:74: instantiated from âvoid std::_Construct(_T1*, const _T2&) [with _T1 = concurrent_queue<Packet*>, _T2 = concurrent_queue<Packet*>]â
/usr/include/c++/4.4/bits/stl_uninitialized.h:187: instantiated from âstatic void std::__uninitialized_fill_n<<anonymous> >::uninitialized_fill_n(_ForwardIterator, _Size, const _Tp&) [with _ForwardIterator = concurrent_queue<Packet*>*, _Size = long unsigned int, _Tp = concurrent_queue<Packet*>, bool <anonymous> = false]â
/usr/include/c++/4.4/bits/stl_uninitialized.h:223: instantiated from âvoid std::uninitialized_fill_n(_ForwardIterator, _Size, const _Tp&) [with _ForwardIterator = concurrent_queue<Packet*>*, _Size = long unsigned int, _Tp = concurrent_queue<Packet*>]â
/usr/include/c++/4.4/bits/stl_uninitialized.h:318: instantiated from âvoid std::__uninitialized_fill_n_a(_ForwardIterator, _Size, const _Tp&, std::allocator<_Tp2>&) [with _ForwardIterator = concurrent_queue<Packet*>*, _Size = long unsigned int, _Tp = concurrent_queue<Packet*>, _Tp2 = concurrent_queue<Packet*>]â
/usr/include/c++/4.4/bits/stl_vector.h:1035: instantiated from âvoid std::vector<_Tp, _Alloc>::_M_fill_initialize(size_t, const _Tp&) [with _Tp = concurrent_queue<Packet*>, _Alloc = std::allocator<concurrent_queue<Packet*> >]â
/usr/include/c++/4.4/bits/stl_vector.h:230: instantiated from âstd::vector<_Tp, _Alloc>::vector(size_t, const _Tp&, const _Alloc&) [with _Tp = concurrent_queue<Packet*>, _Alloc = std::allocator<concurrent_queue<Packet*> >]â
test.cpp:18: instantiated from here
concurrentqueue.h:24: error: no match for call to â(boost::mutex) (boost::mutex&)â
编辑:
boost mutex似乎继承了不可复制的条件变量,我认为是相同的。