tf::BoundedTaskQueue
taskflow/core/tsq.hpp
typename T
size_t LogSize LogSize TF_DEFAULT_BOUNDED_TASK_QUEUE_LOG_SIZE
constexpr static int64_t constexpr static int64_t tf::BoundedTaskQueue< T, LogSize >::BufferSize BufferSize = int64_t{1} << LogSize
constexpr static int64_t constexpr static int64_t tf::BoundedTaskQueue< T, LogSize >::BufferMask BufferMask = (BufferSize - 1)
std::atomic< int64_t > std::atomic<int64_t> tf::BoundedTaskQueue< T, LogSize >::_top _top {0}
std::atomic< int64_t > std::atomic<int64_t> tf::BoundedTaskQueue< T, LogSize >::_bottom _bottom {0}
std::atomic< T > std::atomic<T> tf::BoundedTaskQueue< T, LogSize >::_buffer[BufferSize] [BufferSize] _buffer
tf::BoundedTaskQueue< T, LogSize >::BoundedTaskQueue
()=default
BoundedTaskQueue

constructs the queue with a given capacity

tf::BoundedTaskQueue< T, LogSize >::~BoundedTaskQueue
()=default
~BoundedTaskQueue

destructs the queue

bool bool tf::BoundedTaskQueue< T, LogSize >::empty () const noexcept empty

queries if the queue is empty at the time of this call

size_t size_t tf::BoundedTaskQueue< T, LogSize >::size () const noexcept size

queries the number of items at the time of this call

constexpr size_t constexpr size_t tf::BoundedTaskQueue< T, LogSize >::capacity () const capacity

queries the capacity of the queue

typename O
bool bool tf::BoundedTaskQueue< T, LogSize >::try_push (O &&item) try_push O && item

tries to insert an item to the queue

O

data type

item

the item to perfect-forward to the queue

`true` if the insertion succeed or `false` (queue is full)

Only the owner thread can insert an item to the queue.
typename O
typename C
void void tf::BoundedTaskQueue< T, LogSize >::push (O &&item, C &&on_full) push O && item C && on_full

tries to insert an item to the queue or invoke the callable if fails

O

data type

C

callable type

item

the item to perfect-forward to the queue

on_full

callable to invoke when the queue is faull (insertion fails)

Only the owner thread can insert an item to the queue.
T T tf::BoundedTaskQueue< T, LogSize >::pop () pop

pops out an item from the queue

Only the owner thread can pop out an item from the queue. The return can be a std::nullopt if this operation failed (empty queue).

T T tf::BoundedTaskQueue< T, LogSize >::steal () steal

steals an item from the queue

Any threads can try to steal an item from the queue. The return can be a std::nullopt if this operation failed (not necessary empty).

class to create a lock-free bounded single-producer multiple-consumer queue

T

data type

LogSize

the base-2 logarithm of the queue size

This class implements the work-stealing queue described in the paper, "Correct and Efficient Work-Stealing for Weak Memory Models," available at https://www.di.ens.fr/~zappa/readings/ppopp13.pdf.

Only the queue owner can perform pop and push operations, while others can steal data from the queue.

- tf::BoundedTaskQueue
  _bottom
- tf::BoundedTaskQueue
  _buffer
- tf::BoundedTaskQueue
  _top
- tf::BoundedTaskQueue
  BoundedTaskQueue
- tf::BoundedTaskQueue
  BufferMask
- tf::BoundedTaskQueue
  BufferSize
- tf::BoundedTaskQueue
  capacity
- tf::BoundedTaskQueue
  empty
- tf::BoundedTaskQueue
  pop
- tf::BoundedTaskQueue
  push
- tf::BoundedTaskQueue
  size
- tf::BoundedTaskQueue
  steal
- tf::BoundedTaskQueue
  try_push
- tf::BoundedTaskQueue
  ~BoundedTaskQueue