when i declare my queue as
typedef boost::lockfree::queue<MyMessage, boost::lockfree::fixed_sized<true>> MessageQueue
and i try to use the queue as a multiple-producer-single-consumer queue, i.e. post messages to it from multiple threads and poll the queue for messages from a single thread, the consumer thread gets locked. nothing moves forward.
but when i don't use the fixed size property, i.e. don't specify the template parameter fixed_sized<true> , the queue works fine. But in this case the queue actually does a memory allocation/deallocation which defeats the purpose of using a lockless queue.
So my question is "does boost::lockfree::queue becomes a single-producer-single-consumer queue if set with the property fixed_sized<true>?"
is there some different push/pop methods i need to use?
I want an MPMC queue which does not do memory allocation deallocation. if boost does not provide this, is there any other queue that i can use??
Thanks in advance,
fixed_sizepolicy. Additionally, the boost lock-free queue "uses a freelist for memory management, freed nodes are pushed to the freelist and not returned to the OS before the queue is destroyed" (per default) therefore memory allocation does not occur for everypushoperation even w/ofixed_size. Please provide a SSCCE. - dypfixed_sizepolicy, the queue gets stuck if multiple threads callpush(). It doesnt get stuck if i ensure that only a single thread callspush(). How to explain this? - weimapushis documented to be "thread-safe", it would really be nice if you could post a small code example that replicates the problem. Maybe it's even a bug in the boost version you're using. As far as I can see the documentation says it's mutli-write/multi-reader, independent from the policies. - dypfixed_size<true>, the problem doesnt occur. but it does occur in my code. it goes away as soon as i remove thefixed_sizeparameter. i dont know how to explain this. - weimafixed_size<true>policy implies two changes: if you callpushand no further capacity is available,pushfails and returnsfalse. Additionally, the maximum capacity that can be set is limited typically to2**16-2elements. You'll have to manually set the capacity via the ctorqueue(size_type)or thereservemember function, the default ctor will set the capacity to0. For a capacity of0, everypushwill fail. - dyp