concurrent_bounded_queue Template Class¶
Summary¶
Template class for bounded dual queue with concurrent operations.
Syntax¶
template<typename T, class Alloc=cache_aligned_allocator<T> >
class concurrent_bounded_queue;
Header¶
#include "tbb/concurrent_queue.h"
Description¶
A
concurrent_bounded_queue
is similar to a
concurrent_queue
, but with the following differences:
Adds the ability to specify a capacity. The default capacity makes the queue practically unbounded.
Changes the
push
operation so that it waits until it can complete without exceeding the capacity.Adds a waiting
pop
operation that waits until it can pop an item.Changes the
size_type
to a signed type.Changes the
size()
operation to return the number of push operations minus the number of pop operations. For example, if there are 3 pop operations waiting on an empty queue,size()
returns 3.Adds an
abort
operation that causes any waitingpush
orpop
operation to abort and throw an exception.
Members¶
To aid comparison, the parts that differ from
concurrent_queue
are in bold and annotated.
namespace tbb {
template<typename T, typename A=cache_aligned_allocator<T> >
class concurrent_bounded_queue {
public:
// types
typedef T value_type;
typedef A allocator_type;
typedef T& reference;
typedef const T& const_reference;
// size_type is signed type
typedef std::ptrdiff_t size_type;
typedef std::ptrdiff_t difference_type;
explicit concurrent_bounded_queue(const allocator_type& a = allocator_type());
concurrent_bounded_queue( const concurrent_bounded_queue& src, const allocator_type& a = allocator_type());
template<typename InputIterator>
concurrent_bounded_queue( InputIterator begin, InputIterator end, const allocator_type& a = allocator_type());
// Supported since C++11
concurrent_bounded_queue( concurrent_bounded_queue&& src );
concurrent_bounded_queue( concurrent_bounded_queue&& src, const allocator_type& a );
~concurrent_bounded_queue();
// waits until it can push without exceeding capacity.
void push( const T& source );
// waits if *this is empty
void pop( T& destination );
// Supported since C++11
void push( T&& source );
// the same as push except that the item is constructed with given arguments.
template<typename... Arguments>
void emplace(Arguments&&... args);
// skips push if it would exceed capacity.
bool try_push( const T& source );
bool try_pop( T& destination );
// Supported since C++11
bool try_push( T&& source );
// the same as try_push except that the item is constructed with given arguments.
template<typename... Arguments>
bool try_emplace(Arguments&&... args);
void abort();
void clear();
// safe to call during concurrent modification, can return negative size.
size_type size() const;
bool empty() const;
size_type capacity() const;
void set_capacity( size_type capacity );
allocator_type get_allocator() const;
typedef implementationdefined iterator;
typedef implementationdefined const_iterator;
// iterators (these are slow an intended only for debugging)
iterator unsafe_begin();
iterator unsafe_end();
const_iterator unsafe_begin() const;
const_iterator unsafe_end() const;
};
}
Because
concurrent_bounded_queue
is similar to
concurrent_queue
, the following table describes only
methods that differ.
Member, Description 




























See also: