LibraryLink Utilities  3.0.1
Modern C++ wrapper over LibraryLink and WSTP
LLU::Async::WorkStealingQueue< BaseQueue > Class Template Reference

Description

template<typename BaseQueue>
class LLU::Async::WorkStealingQueue< BaseQueue >

Wrapper class around a queue, that provides the interface for work stealing.

Work stealing is when one thread pops a task from another thread's queue. In WorkStealingQueue tasks are popped from the front and stolen from the back.

Template Parameters
BaseQueue- any class implementing a queue with push_front, push_back, pop_front, pop_back, empty, front and back methods.

#include <WorkStealingQueue.h>

Public Member Functions

void push (DataType data)
 Push new element to the beginning of the queue. More...
 
bool empty () const
 Check if the queue is empty. More...
 
bool tryPop (DataType &res)
 Try to pop a task from the beginning of the queue in a non-blocking way. More...
 
bool trySteal (DataType &res)
 Try to pop a task from the end of the queue (this is what we call "stealing") in a non-blocking way. More...
 

Member Function Documentation

◆ empty()

template<typename BaseQueue >
bool LLU::Async::WorkStealingQueue< BaseQueue >::empty ( ) const
inline

Check if the queue is empty.

Returns
true iff the queue is empty

◆ push()

template<typename BaseQueue >
void LLU::Async::WorkStealingQueue< BaseQueue >::push ( DataType  data)
inline

Push new element to the beginning of the queue.

Parameters
data- new element

◆ tryPop()

template<typename BaseQueue >
bool LLU::Async::WorkStealingQueue< BaseQueue >::tryPop ( DataType &  res)
inline

Try to pop a task from the beginning of the queue in a non-blocking way.

Parameters
[out]res- reference to which the new task should be assigned
Returns
true iff the queue was not empty and a task was popped

◆ trySteal()

template<typename BaseQueue >
bool LLU::Async::WorkStealingQueue< BaseQueue >::trySteal ( DataType &  res)
inline

Try to pop a task from the end of the queue (this is what we call "stealing") in a non-blocking way.

Parameters
[out]res- reference to which the new task should be assigned
Returns
true iff the queue was not empty and a task was popped