我在放入boost::lockfree::queue<<T, fixed_sized<false>, ..>
共享内存时遇到问题.我需要它,因为我必须能够将超过65535条消息插入队列,并且fixed_sized队列限制为65535.
以下代码正常工作(但capacity<...>选项暗示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);
Run Code Online (Sandbox Code Playgroud)
以下代码也正常工作(但它不使用共享内存):
boost::lockfree::queue<MessageT> q;
....
q.bounded_push(message);
Run Code Online (Sandbox Code Playgroud)
但是当我尝试将它结合起来时:
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);
Run Code Online (Sandbox Code Playgroud)
它无法使用以下日志进行编译:
In file included from src/model/Queue.h:16:
In file included from /home/uppi/lib/include/boost/lockfree/queue.hpp:24: …Run Code Online (Sandbox Code Playgroud)