I would like to know if a spsc_queue
from Boost.LockFree
can be used with user-defined types. From the examples I am not sure, I just see atomic
s and more atomic
s.
我想知道Boost.LockFree中的spsc_queue是否可以与用户定义的类型一起使用。从我不确定的例子中,我只看到原子和更多的原子。
Example:
例:
boost::lockfree::spsc_queue<int, boost::lockfree::capacity<1024> > spsc_queue;
So, can I do this?
那么,我可以这样做吗?
boost::lockfree::spsc_queue<ServerReply, boost::lockfree::capacity<1024> > spsc_queue;
I am wondering if only basic types and pointers can be stored, since popping things, etc must be done atomically, but ServerReply is a compound type.
我想知道是否只能存储基本类型和指针,因为弹出的东西等必须以原子方式完成,但ServerReply是复合类型。
1 个解决方案
#1
3
The short answer YES.
简短回答是的。
Though it was to a slightly different question, I've explained exactly how and why this is in a previous answer that dives into the "proof": the library code as well:
虽然这是一个稍微不同的问题,但我已经解释了在以前的答案中如何以及为什么会潜入“证明”:库代码:
- boost lockfree spsc_queue cache memory access
- boost lockfree spsc_queue缓存内存访问
You can be pretty confident that if it compiles, it's probably supposed to be allowed.
你可以非常自信,如果它编译,它可能应该被允许。
Notable exception is that there is no runtime verification of the fact that there are indeed only a single producer and a single consumer, but you got that requirement, no doubt.
值得注意的例外是,没有运行时验证事实上确实只有一个生产者和一个消费者,但毫无疑问,你有这个要求。
#1
3
The short answer YES.
简短回答是的。
Though it was to a slightly different question, I've explained exactly how and why this is in a previous answer that dives into the "proof": the library code as well:
虽然这是一个稍微不同的问题,但我已经解释了在以前的答案中如何以及为什么会潜入“证明”:库代码:
- boost lockfree spsc_queue cache memory access
- boost lockfree spsc_queue缓存内存访问
You can be pretty confident that if it compiles, it's probably supposed to be allowed.
你可以非常自信,如果它编译,它可能应该被允许。
Notable exception is that there is no runtime verification of the fact that there are indeed only a single producer and a single consumer, but you got that requirement, no doubt.
值得注意的例外是,没有运行时验证事实上确实只有一个生产者和一个消费者,但毫无疑问,你有这个要求。