Assertion fails in case of boost :: lockfree: default constructor by default

How can I use boost::lockfree:queue objects?

I am trying to write an application that builds an object of this class using the default constructor, but this gives me an assertion error inside boost sources:

 BOOST_ASSERT(has_capacity); 

How can I use the default constructor for this class? Do I need to specify the size of the queue using the template arguments?

+7
c ++ boost lock-free
source share
2 answers

Capacity can be set statically, so even up to the default constructor.

 boost::lockfree::queue<int, boost::lockfree::capacity<50> > my_queue; 

The mechanism is similar to named parameters for template arguments.

Watch Live On Coliru

 #include <boost/lockfree/queue.hpp> #include <iostream> using namespace boost::lockfree; struct X { int i; std::string s; }; int main() { queue<int, boost::lockfree::capacity<50> > q; } 
+7
source share

Instead , you can use the queue size_type constructor , for example:

 #include <iostream> #include <boost/lockfree/queue.hpp> int main() { boost::lockfree::queue<int> queue( 0 ); int pushed = 4; int popped = 0; if( queue.push( pushed ) ) { std::cout << "Pushed " << pushed << std::endl; } if( queue.pop( popped ) ) { std::cout << "Popped " << popped << std::endl; } return 0; } 
0
source share

All Articles