Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one make a boost::lockfree::queue be dynamically resizing

Tags:

c++

boost

The documentation for boost::lockfree::queue mentions that push can allocate more space if need be. However I can't for the life of me figure out how to instantiate such a queue and I can't find an example of it. All of the examples on boost's website are of fixed capacity.

This is the documentation I was looking at: http://www.boost.org/doc/libs/1_54_0/doc/html/boost/lockfree/queue.html

like image 376
Joe Doliner Avatar asked Apr 06 '14 08:04

Joe Doliner


1 Answers

The default is for the queue to be variable sized. This is controlled by the typename ...Options template parameter.

Further, there is a bug which in which the queue demands a statically set capacity, even when the queue is variable sized. This can be avoided by using the constructor that takes an initial capacity.

A variable sized queue can be instantiated as:

boost::lockfree::queue<T> newQueue(0);
// or equivalently:
boost::lockfree::queue<T, boost::lockfree::fixed_sized<false> > newQueue(0);

A fixed sized queue must explicitly set the fixed_sized option to true or supply a size with the boost::lockfree::capacity option.

See the Policies section near the start of the documentation that you linked to.

like image 182
Mankarse Avatar answered Oct 12 '22 12:10

Mankarse