使用带有分配器的 boost::lockfree::spsc_queue
Using boost::lockfree::spsc_queue with an allocator
以下是我问题的表示。
#include <boost/lockfree/spsc_queue.hpp>
class test {
struct complicated {
int x;
int y;
};
std::allocator<complicated> alloc;
boost::lockfree::spsc_queue<complicated,
boost::lockfree::allocator<std::allocator<complicated> > > spsc;
test(void);
};
test::test(void): spsc( alloc ) {};
使用此代码,我在VS2010中遇到以下错误:
错误 C2512:"提升::无锁定::d尾巴::runtime_sized_ringbuffer":没有可用的适当默认构造函数
编译类模板成员函数 'boost::lockfree::spsc_queue::spsc_queue(const std::allocator<_Ty> &)'
错误消息指出它正在编译一个带有一个参数的构造函数,我认为它应该是分配器,但主要错误涉及默认构造函数。
文档的起点是 http://www.boost.org/doc/libs/1_54_0/doc/html/lockfree.html。
定义 boost::lockfree::spsc_queue 和 boost::lockfree::分配器的适当机制是什么?
根据 boost 源代码,由于您没有为spsc_queue
指定编译时容量,因此spsc_queue
的基类通过 typedefs 和模板魔术解析为具有以下构造函数runtime_sized_ringbuffer
:
explicit runtime_sized_ringbuffer(size_t max_elements);
template <typename U>
runtime_sized_ringbuffer(typename Alloc::template rebind<U>::other const & alloc, size_t max_elements);
runtime_sized_ringbuffer(Alloc const & alloc, size_t max_elements);
如您所见,所有这些构造函数都需要一个max_element
参数。提供此功能的唯一方法是使用以下spsc_queue
构造函数之一:
explicit spsc_queue(size_type element_count):
base_type(element_count)
{
BOOST_ASSERT(runtime_sized);
}
template <typename U>
spsc_queue(size_type element_count, typename allocator::template rebind<U>::other const & alloc):
base_type(alloc, element_count)
{
BOOST_STATIC_ASSERT(runtime_sized);
}
spsc_queue(size_type element_count, allocator_arg const & alloc):
base_type(alloc, element_count)
{
BOOST_ASSERT(runtime_sized);
}
换句话说,尝试在调用spsc_queue
构造函数时提供大小和分配器。
相关文章:
- ARM 上的无锁 SPSC 队列实现
- 哪个架构更好?多个 SPSC 队列或一个 MPSC 队列
- boost::lockfree::spsc_queue and boost::asio
- 如何使用boost :: lockfree ::队列实体填充容器
- 使用boost.lockfree队列比使用静音速度慢
- 如果这不是 boost::lockfree::d etail::freelist 中的错误,我在这里错过了什么
- 是boost :: lockfree :: Queue(在多线程程序中)可锁定
- boost :: lockfree ::队列正在吃我的CPU
- 在 boost::lockfree:queue 默认构造函数的情况下断言失败
- boost::lockfree-为排队的元素调用析构函数
- 在 Folly 的无锁 SPSC 队列中使用 std::memory_order_consume
- boost::lockfree::queue允许的数据结构示例
- 使用带有分配器的 boost::lockfree::spsc_queue
- SPSC锁定免费队列,无原子
- boost::lockfree::队列似乎没有释放内存,尽管每个集合对象上的析构函数都被调用
- 如何将std::string放入boost::lockfree::queue(或备选方案)
- {错误 C2338: (boost::has_trivial_destructor:<T>:value)} 对于 boost::lockfree::queue 是什么意思?我在这里错过了什
- Boost spsc队列段故障
- /boost/lockfree/queue.hpp:错误:静态断言失败:(boost::has_trivial_destructor<T>::value)
- 在c++11中,boost::lockfree::queue不是lockfree的