У меня проблема с размещением 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);
Следующий код тоже работает правильно (но он не использует разделяемую память):
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
Пожалуйста, скажите мне, что мне не хватает
с помощью boost::lockfree::queue
или же boost::lockfree::stack
в общей памяти ограничено 65535 элементами, по соображениям совместимости. если у вас есть сценарий использования с одним производителем, вы можете использовать boost::lockfree::spsc_queue
, однако это также не динамический размер.
Причиной этого является ограничение 32-битной совместимости. для 64-битных платформ можно адаптировать код boost.lockfree для использования 32-битных вместо 16-битных индексов. но это потребовало бы некоторых нетривиальных изменений для правильной реализации.
Других решений пока нет …