Cpp-Taskflow  2.3.1
tf::TaskQueue< T > Class Template Reference

Lock-free unbounded single-producer multiple-consumer queue. More...

#include <tsq.hpp>

Public Member Functions

 TaskQueue (int64_t capacity=1024)
 constructs the queue with a given capacity More...
 
 ~TaskQueue ()
 destructs the queue
 
bool empty () const noexcept
 queries if the queue is empty at the time of this call
 
size_t size () const noexcept
 queries the number of items at the time of this call
 
int64_t capacity () const noexcept
 queries the capacity of the queue
 
void push (T item)
 inserts an item to the queue More...
 
pop ()
 pops out an item from the queue More...
 
steal ()
 steals an item from the queue More...
 

Detailed Description

template<typename T>
class tf::TaskQueue< T >

Lock-free unbounded single-producer multiple-consumer queue.

Template Parameters
Tdata type (must be a pointer)

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.

Constructor & Destructor Documentation

◆ TaskQueue()

template<typename T >
tf::TaskQueue< T >::TaskQueue ( int64_t  capacity = 1024)
explicit

constructs the queue with a given capacity

Parameters
capacitythe capacity of the queue (must be power of 2)

Member Function Documentation

◆ pop()

template<typename T >
T tf::TaskQueue< T >::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 nullptr if this operation failed (empty queue).

◆ push()

template<typename T>
void tf::TaskQueue< T >::push ( item)

inserts an item to the queue

Only the owner thread can insert an item to the queue. The operation can trigger the queue to resize its capacity if more space is required.

Template Parameters
Odata type
Parameters
itemthe item to perfect-forward to the queue

◆ steal()

template<typename T >
T tf::TaskQueue< T >::steal ( )

steals an item from the queue

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


The documentation for this class was generated from the following file: