2013-02-15 12 views
8

मुझे साझा स्मृति में boost::lockfree::queue<<T, fixed_sized<false>, ..> रखने में समस्या है। मैं इसे की जरूरत है क्योंकि मैं कतार में एक से अधिक 65535 गए संदेशों डालने के लिए सक्षम होने के लिए है, और fixed_sized कतार 65535
निम्नलिखित कोड ठीक से काम करता साथ सीमित है (लेकिन capacity<...> विकल्प fixed_sized<true> का तात्पर्य):बूस्ट के साथ परेशानी :: लॉकफ्री :: साझा मेमोरी में कतार (बूस्ट 1.53, जीसीसी 4.7.2/क्लैंग 3.0-6ubuntu3)

typedef boost::interprocess::allocator< 
    MessageT, 
    boost::interprocess::managed_shared_memory::segment_manager> 
     ShmemAllocator; 
typedef boost::lockfree::queue< 
    MessageT, 
    boost::lockfree::capacity<65535>, 
    boost::lockfree::allocator<ShmemAllocator> > 
     Queue; 
m_segment = new boost::interprocess::managed_shared_memory(
    boost::interprocess::create_only, segmentName, size); 
Queue* m_queue = m_segment->construct<Queue>(
    queueName)(
    m_segment->get_segment_manager()); 
... 
m_queue->bounded_push(message); 

निम्नलिखित कोड काम करता है ठीक से भी (लेकिन यह साझा स्मृति का उपयोग नहीं करता):

boost::lockfree::queue<MessageT> q; 
.... 
q.bounded_push(message); 

लेकिन जब मैंने उसे गठबंधन करने के लिए प्रयास करें:

typedef boost::interprocess::allocator< 
    MessageT, 
    boost::interprocess::managed_shared_memory::segment_manager> 
     ShmemAllocator; 
typedef boost::lockfree::queue< 
    MessageT, 
    boost::lockfree::allocator<ShmemAllocator> > 
     Queue; 
m_segment = new boost::interprocess::managed_shared_memory(
    boost::interprocess::create_only, segmentName, size); 
Queue* m_queue = m_segment->construct<Queue>(
    queueName)(
    m_segment->get_segment_manager()); 
... 
m_queue->bounded_push(message); 

यह निम्नलिखित लॉग के साथ संकलित करने के लिए विफल रहता है:

In file included from src/model/Queue.h:16: 

In file included from /home/uppi/lib/include/boost/lockfree/queue.hpp:24: 

/home/uppi/lib/include/boost/lockfree/detail/freelist.hpp:171:28: error: no viable conversion from 'pointer' (aka 'offset_ptr<boost::lockfree::queue<PacketMessage, 
     boost::lockfree::allocator<boost::interprocess::allocator<PacketMessage, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, 
     boost::interprocess::offset_ptr<void, long, unsigned long, 0>, 0>, iset_index> > >, boost::parameter::void_, boost::parameter::void_>::node, long, unsigned long, 0UL>') to 
     'boost::lockfree::queue<PacketMessage, boost::lockfree::allocator<boost::interprocess::allocator<PacketMessage, boost::interprocess::segment_manager<char, 
     boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long, unsigned long, 0>, 0>, iset_index> > >, boost::parameter::void_, 
     boost::parameter::void_>::node *' 
        return Alloc::allocate(1); 
          ~~~~~~~~~~~~~~~~~ 

/home/uppi/lib/include/boost/lockfree/detail/freelist.hpp:157:20: note: in instantiation of function template specialization 'boost::lockfree::detail::freelist_stack<boost::lockfree::queue<PacketMessage, 
     boost::lockfree::allocator<boost::interprocess::allocator<PacketMessage, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, 
     boost::interprocess::offset_ptr<void, long, unsigned long, 0>, 0>, iset_index> > >, boost::parameter::void_, boost::parameter::void_>::node, 
     boost::interprocess::allocator<boost::lockfree::queue<PacketMessage, boost::lockfree::allocator<boost::interprocess::allocator<PacketMessage, boost::interprocess::segment_manager<char, 
     boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long, unsigned long, 0>, 0>, iset_index> > >, boost::parameter::void_, 
     boost::parameter::void_>::node, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long, unsigned 
     long, 0>, 0>, iset_index> > >::allocate_impl<true>' requested here 
      return allocate_impl<Bounded>(); 


/home/uppi/lib/include/boost/lockfree/detail/freelist.hpp:89:20: note: in instantiation of function template specialization 'boost::lockfree::detail::freelist_stack<boost::lockfree::queue<PacketMessage, 
     boost::lockfree::allocator<boost::interprocess::allocator<PacketMessage, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, 
     boost::interprocess::offset_ptr<void, long, unsigned long, 0>, 0>, iset_index> > >, boost::parameter::void_, boost::parameter::void_>::node, 
     boost::interprocess::allocator<boost::lockfree::queue<PacketMessage, boost::lockfree::allocator<boost::interprocess::allocator<PacketMessage, boost::interprocess::segment_manager<char, 
     boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long, unsigned long, 0>, 0>, iset_index> > >, boost::parameter::void_, 
     boost::parameter::void_>::node, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long, unsigned 
     long, 0>, 0>, iset_index> > >::allocate<true, true>' requested here 
     T * node = allocate<ThreadSafe, Bounded>(); 


/home/uppi/lib/include/boost/lockfree/queue.hpp:281:34: note: in instantiation of function template specialization 'boost::lockfree::detail::freelist_stack<boost::lockfree::queue<PacketMessage, 
     boost::lockfree::allocator<boost::interprocess::allocator<PacketMessage, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, 
     boost::interprocess::offset_ptr<void, long, unsigned long, 0>, 0>, iset_index> > >, boost::parameter::void_, boost::parameter::void_>::node, 
     boost::interprocess::allocator<boost::lockfree::queue<PacketMessage, boost::lockfree::allocator<boost::interprocess::allocator<PacketMessage, boost::interprocess::segment_manager<char, 
     boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long, unsigned long, 0>, 0>, iset_index> > >, boost::parameter::void_, 
     boost::parameter::void_>::node, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long, unsigned 
     long, 0>, 0>, iset_index> > >::construct<true, true, PacketMessage, boost::lockfree::queue<PacketMessage, boost::lockfree::allocator<boost::interprocess::allocator<PacketMessage, 
     boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long, unsigned long, 0>, 0>, iset_index> > >, 
     boost::parameter::void_, boost::parameter::void_>::node *>' requested here 
     node * n = pool.template construct<true, Bounded>(t, pool.null_handle()); 


/home/uppi/lib/include/boost/lockfree/queue.hpp:270:16: note: in instantiation of function template specialization 'boost::lockfree::queue<PacketMessage, 
     boost::lockfree::allocator<boost::interprocess::allocator<PacketMessage, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, 
     boost::interprocess::offset_ptr<void, long, unsigned long, 0>, 0>, iset_index> > >, boost::parameter::void_, boost::parameter::void_>::do_push<true>' requested here 
     return do_push<true>(t); 


src/model/Queue.inl:4:18: note: in instantiation of member function 'boost::lockfree::queue<PacketMessage, boost::lockfree::allocator<boost::interprocess::allocator<PacketMessage, 
     boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long, unsigned long, 0>, 0>, iset_index> > >, 
     boost::parameter::void_, boost::parameter::void_>::bounded_push' requested here 
     return m_queue->bounded_push(message);       

/home/uppi/lib/include/boost/interprocess/offset_ptr.hpp:450:4: note: candidate function 
    operator unspecified_bool_type() const 

कृपया मुझे बताओ कि मैं

+0

आप टिम ब्लेचमैन, lockfree के लेखक से पूछते हैं, इस बारे में था? वह आमतौर पर काफी मददगार होता है। – eile

+0

धन्यवाद, मैं सिर्फ उसे एक ई-मेल – uppi

उत्तर

14

साझा स्मृति में boost::lockfree::queue या boost::lockfree::stack का उपयोग कर याद कर रहा हूँ संगतता कारणों के लिए, 65535 तत्व तक सीमित है। यदि आपके पास एकल निर्माता, एकल-उपभोक्ता उपयोग-केस है, तो आप boost::lockfree::spsc_queue का उपयोग करना चाहेंगे। हालांकि यह गतिशील रूप से आकार भी नहीं है। इस के लिए

कारण सीमा 32 बिट संगतता है। 64 बिट प्लेटफ़ॉर्म के लिए 16 बिट इंडेक्स के बजाय 32 बिट का उपयोग करने के लिए boost.lockfree कोड को अनुकूलित करने में सक्षम हो सकता है। लेकिन चीजों को सही ढंग से कार्यान्वित करने के लिए इसमें कुछ गैर-तुच्छ परिवर्तनों की आवश्यकता होगी।

+0

स्पष्टीकरण – uppi

+0

@timblechmann के लिए धन्यवाद भेज दिया है लेकिन अगर मंच x86_64 वहाँ 10 वर्षों के लिए पहले से ही है, तो क्यों बढ़ावा के 64 बिट कार्यान्वयन :: lockfree :: कतार लागू नहीं किया है? – Alex

+0

@ एलेक्स बस अपने हाथ गंदे पाएं और एक पैच प्रदान करें जो डेटा संरचना को कॉन्फ़िगर करने के लिए नीति जोड़ता है;) – timblechmann

संबंधित मुद्दे