We would like to know the number of element in the queue at a given point of time. We are pushing and popping objects, we would like to know the number of object in the Queue buffer. Is there any inbuilt function for this ? Or some other way to get it ?
http://www.boost.org/doc/libs/1_53_0/doc/html/boost/lockfree/spsc_queue.html
You can't reliably get the size because it invites race conditions. For the same reason, you won't find the empty() method: by the time the method returned a value, it will be irrelevant, because it might have changed.
Sometimes lockfree containers provide an "unreliable_size()" method (for purposes of statistics/logging)
The special case here is that SPSC assume single producer and consumers:
size_type read_available() const;
number of available elements that can be popped from the spsc_queue
size_type write_available() const;
get write space to write elements
Note these are only valid when used from the respective consumer/producer thread.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With