Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Observe size of lockfree queue

all

I'm trying to use the boost library's lock free queue data structure.

#include <boost/thread/thread.hpp>
#include <boost/lockfree/queue.hpp>

However, I found out that these data structure do not support methods to get the number of current entries that these are containing (http://www.boost.org/doc/libs/1_53_0/doc/html/boost/lockfree/queue.html).

What I want is something similar to std::queue::size (http://en.cppreference.com/w/cpp/container/queue/size).

Thanks a lot for your help in advance!

like image 791
kjee Avatar asked Dec 19 '14 22:12

kjee


1 Answers

If you just want to track high/low water marks, have an atomic counter that you increment when you enqueue, and decrement when you dequeue.

You can periodically sample that counter to do any tuning/statistical analysis that you might need.

The queue itself doesn't supply this operation, because you only pay for what you need.

like image 127
sehe Avatar answered Sep 28 '22 06:09

sehe