Germán Diago
Germán Diago

Reputation: 7663

Boost: spsc queue: can I use it for a user-defined type?

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 atomics and more atomics.

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.

Upvotes: 3

Views: 1987

Answers (1)

sehe
sehe

Reputation: 393064

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:

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.

Upvotes: 3

Related Questions