![]() |
Home | Libraries | People | FAQ | More |
boost::lockfree::queue
// In header: <boost/lockfree/queue.hpp> template<typename T, Options> class queue { public: // types typedef ; typedef ; typedef ; // construct/copy/destruct (); template<typename U> (); (); (); template<typename U> (, ); ~(); // public member functions () ; (); (); () ; (); (); (); (); template<typename U> (); (); template<typename U> (); template<typename Functor> (); template<typename Functor> (); template<typename Functor> (); template<typename Functor> (); };
The queue class provides a multi-writer/multi-reader queue, pushing and popping is lock-free, construction/destruction has to be synchronized. It uses a freelist for memory management, freed nodes are pushed to the freelist and not returned to the OS before the queue is destroyed.
Policies:
boost::lockfree::fixed_sized, defaults to boost::lockfree::fixed_sized<false>
Can be used to completely disable dynamic memory allocations during push in order to ensure lockfree behavior.
If the data structure is configured as fixed-sized, the internal nodes are stored inside an array and they are addressed by array indexing. This limits the possible size of the queue to the number of elements that can be addressed by the index type (usually 2**16-2), but on platforms that lack double-width compare-and-exchange instructions, this is the best way to achieve lock-freedom.
boost::lockfree::capacity, optional
If this template argument is passed to the options, the size of the queue is set at compile-time.
This option implies fixed_sized<true>
boost::lockfree::allocator, defaults to boost::lockfree::allocator<std::allocator<void>>
Specifies the allocator that is used for the internal freelist
Requirements:
T must have a copy constructor
T must have a trivial assignment operator
T must have a trivial destructor
queue
public
construct/copy/destruct();
Construct a fixed-sized queue
Requires: |
Must specify a capacity<> argument |
template<typename U> ( alloc);
Construct a fixed-sized queue with a custom allocator
Requires: |
Must specify a capacity<> argument |
( alloc);
Construct a fixed-sized queue with a custom allocator
Requires: |
Must specify a capacity<> argument |
( n);
Construct a variable-sized queue
Allocate n nodes initially for the freelist
Requires: |
Must not specify a capacity<> argument |
template<typename U> ( n, alloc);
Construct a variable-sized queue with a custom allocator
Allocate n nodes initially for the freelist
Requires: |
Must not specify a capacity<> argument |
~();
Destroys queue, free all nodes from freelist.
queue
public member functions() ;
![]() |
Warning |
---|---|
It only checks, if the queue head and tail nodes and the freelist can be modified in a lock-free manner. On most platforms, the whole implementation is lock-free, if this is true. Using c++0x-style atomics, there is no possibility to provide a completely accurate implementation, because one would need to test every internal node, which is impossible if further nodes will be allocated from the operating system. |
Returns: |
true, if implementation is lock-free. |
( n);
Allocate n nodes for freelist
![]() |
Note |
---|---|
thread-safe, may block if memory allocator blocks |
Requires: |
only valid if no capacity<> argument given |
( n);
Allocate n nodes for freelist
![]() |
Note |
---|---|
not thread-safe, may block if memory allocator blocks |
Requires: |
only valid if no capacity<> argument given |
() ;
Check if the queue is empty
![]() |
Note |
---|---|
The result is only accurate, if no other thread modifies the queue. Therefore it is rarely practical to use this value in program logic. |
Returns: |
true, if the queue is empty, false otherwise |
( t);
Pushes object t to the queue.
![]() |
Note |
---|---|
Thread-safe. If internal memory pool is exhausted and the memory pool is not fixed-sized, a new node will be allocated from the OS. This may not be lock-free. |
Postconditions: |
object will be pushed to the queue, if internal node can be allocated |
Returns: |
true, if the push operation is successful. |
( t);
Pushes object t to the queue.
![]() |
Note |
---|---|
Thread-safe and non-blocking. If internal memory pool is exhausted, operation will fail |
Postconditions: |
object will be pushed to the queue, if internal node can be allocated |
Returns: |
true, if the push operation is successful. |
Throws: |
if memory allocator throws |
( t);
Pushes object t to the queue.
![]() |
Note |
---|---|
Not Thread-safe. If internal memory pool is exhausted and the memory pool is not fixed-sized, a new node will be allocated from the OS. This may not be lock-free. |
Postconditions: |
object will be pushed to the queue, if internal node can be allocated |
Returns: |
true, if the push operation is successful. |
Throws: |
if memory allocator throws |
( ret);
Pops object from queue.
![]() |
Note |
---|---|
Thread-safe and non-blocking |
Postconditions: |
if pop operation is successful, object will be copied to ret. |
Returns: |
true, if the pop operation is successful, false if queue was empty. |
template<typename U> ( ret);
Pops object from queue.
![]() |
Note |
---|---|
Thread-safe and non-blocking |
Requires: |
type U must be constructible by T and copyable, or T must be convertible to U |
Postconditions: |
if pop operation is successful, object will be copied to ret. |
Returns: |
true, if the pop operation is successful, false if queue was empty. |
( ret);
Pops object from queue.
![]() |
Note |
---|---|
Not thread-safe, but non-blocking |
Postconditions: |
if pop operation is successful, object will be copied to ret. |
Returns: |
true, if the pop operation is successful, false if queue was empty. |
template<typename U> ( ret);
Pops object from queue.
![]() |
Note |
---|---|
Not thread-safe, but non-blocking |
Requires: |
type U must be constructible by T and copyable, or T must be convertible to U |
Postconditions: |
if pop operation is successful, object will be copied to ret. |
Returns: |
true, if the pop operation is successful, false if queue was empty. |
template<typename Functor> ( f);
consumes one element via a functor
pops one element from the queue and applies the functor on this object
![]() |
Note |
---|---|
Thread-safe and non-blocking, if functor is thread-safe and non-blocking |
Returns: |
true, if one element was consumed |
template<typename Functor> ( f);
consumes one element via a functor
pops one element from the queue and applies the functor on this object
![]() |
Note |
---|---|
Thread-safe and non-blocking, if functor is thread-safe and non-blocking |
Returns: |
true, if one element was consumed |
template<typename Functor> ( f);
consumes all elements via a functor
sequentially pops all elements from the queue and applies the functor on each object
![]() |
Note |
---|---|
Thread-safe and non-blocking, if functor is thread-safe and non-blocking |
Returns: |
number of elements that are consumed |
template<typename Functor> ( f);
consumes all elements via a functor
sequentially pops all elements from the queue and applies the functor on each object
![]() |
Note |
---|---|
Thread-safe and non-blocking, if functor is thread-safe and non-blocking |
Returns: |
number of elements that are consumed |