Template Class WorkStealingDeque

Nested Relationships

Nested Types

Class Documentation

template<class T>
class WorkStealingDeque

the deque of an owner that pushes and takes, and of thieves that steal

Public Types

using Item = T

the type of the items

Public Functions

explicit WorkStealingDeque(std::size_t capacity = 1024)

an empty deque with a vector of the given capacity

Pre:

capacity >= 2 is a power of 2

WorkStealingDeque(const WorkStealingDeque&) = delete
WorkStealingDeque &operator=(const WorkStealingDeque&) = delete
void push(T x)

pushes x at the bottom, doubling the vector if it is full; only the owner calls it

std::optional<T> take(void)

takes the item at the bottom, the last pushed, nothing if the deque is empty or a thief took the last item first; only the owner calls it

bool steal(T &x)

steals the item at the top, the first pushed, into x; false if the deque is empty or another thread took that item first (and then a thief may try again); any thread may call it

std::size_t size(void) const

the number of items at some moment of the call, for the owner exact

inline bool empty(void) const

true if the deque held no item at some moment of the call

inline std::size_t capacity(void) const

the places of the current vector; only the owner calls it