Boost: spsc queue: can I use it for a custom type?

I would like to know if it is possible to use spsc_queue

from Boost.LockFree

with custom types. From examples I'm not sure, I just see atomic

more atomic

s as well.

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 it is possible to store only basic types and pointers, since popping things up etc. should execute atomically, but ServerReply is a composite type.

+3


source to share


1 answer


The short answer is YES.

While this was a slightly different question, I explained how and why it is in a previous answer that dives into the "proof": also the library code:



You can be sure that if it compiles, it should probably be allowed.

The notable exception is that there is no runtime check for the fact that there really is only one producer and one consumer, but you got that requirement, no doubt about it.

+3


source







All Articles