麻烦的boost :: lockfree ::共享内存队列(1.53提振,GCC 4.7.2 /铛3.0-6ubuntu3) [英] Trouble with boost::lockfree::queue in shared memory (boost 1.53, gcc 4.7.2 / clang 3.0-6ubuntu3)

查看:386
本文介绍了麻烦的boost :: lockfree ::共享内存队列(1.53提振,GCC 4.7.2 /铛3.0-6ubuntu3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有放置一个问题的boost :: lockfree ::队列<< T,fixed_sized<假&gt ;, ..>
在共享存储器中。我需要它,因为我必须要能够插入超过65535的消息到队列中,并fixed_sized队列与65535结果限制
下面code正常工作(但容量< ...> 选项意味着 fixed_sized<真>

I have a problem with placing boost::lockfree::queue<<T, fixed_sized<false>, ..> in shared memory. I need it because I have to be able to insert more than 65535 messages into the queue, and fixed_sized queue is limited with 65535.
The following code works properly (but capacity<...> option implies fixed_sized<true>):

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);

以下code正常工作太(但它不使用共享内存):

The following code works properly too (but it doesn't use shared memory):

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

但是,当我尝试把它结合起来:

But when I try to combine it:

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);

失败与以下日志进行编译:

it fails to compile with the following log:

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

请告诉我,我错过了什么。

Please tell me what I'm missing

推荐答案

使用的boost :: lockfree ::队列的boost :: lockfree: :堆栈共享内存被限制在65535元,出于兼容性考虑。如果你有一个单一的生产者,单消费者使用情况,您可能需要使用的boost :: lockfree :: spsc_queue 。然而,这也是不动态化。

using boost::lockfree::queue or boost::lockfree::stack in shared memory is limited to 65535 elements, for compatibility reasons. if you have a single-producer, single-consumer use-case, you might want to use the boost::lockfree::spsc_queue. however this is also not dynamically-sized.

原因是限制是32位的相容性。对于64位平台之一可能能够适应boost.lockfree code使用32位而不是16位指数。但它需要一些不平凡的变化要正确实现的事情。

reason for this is limitation is 32bit compatibility. for 64bit platforms one might be able to adapt the boost.lockfree code to use 32bit instead of 16bit indices. but it would require some non-trivial changes to implement things correctly.

这篇关于麻烦的boost :: lockfree ::共享内存队列(1.53提振,GCC 4.7.2 /铛3.0-6ubuntu3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆