Cpp-Taskflow
2.0.0
|
Lock-free unbounded single-producer multiple-consumer queue. More...
#include <workstealing_threadpool.hpp>
Public Member Functions | |
WorkStealingQueue (int64_t capacity=4096) | |
constructs the queue with a given capacity More... | |
~WorkStealingQueue () | |
destructs the queue | |
bool | empty () const noexcept |
queries if the queue is empty at the time of this call | |
int64_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 | |
template<typename O > | |
void | push (O &&item) |
inserts an item to the queue More... | |
std::optional< T > | pop () |
pops out an item from the queue More... | |
std::optional< T > | steal () |
steals an item from the queue More... | |
Lock-free unbounded single-producer multiple-consumer queue.
T | data type |
This class implements the work stealing queue described in the paper, "Dynamic Circular Work-stealing Deque," SPAA, 2015. Only the queue owner can perform pop and push operations, while others can steal data from the queue.
tf::WorkStealingQueue< T >::WorkStealingQueue | ( | int64_t | capacity = 4096 | ) |
constructs the queue with a given capacity
capacity | the capacity of the queue (must be power of 2) |
std::optional< T > tf::WorkStealingQueue< 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 std::nullopt if this operation failed (not necessary empty).
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.
O | data type |
item | the item to perfect-forward to the queue |
std::optional< T > tf::WorkStealingQueue< T >::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).