Template Struct Worker

Struct Documentation

template<typename Function>
struct quickpool::loop::Worker

Worker class for parallel loops.

When a worker completes its own range, it steals half of the remaining range of another worker. The number of steals (= only source of contention) is therefore only logarithmic in the number of tasks. The algorithm uses double-width compare-and-swap, which is lock-free on most modern processor architectures.

tparam type

of function processing the loop (required to account for type-erasure).

Public Functions

inline Worker()
inline Worker(int begin, int end, Function fun)
inline Worker(Worker &&other)
inline size_t tasks_left() const
inline bool done() const
inline void run(std::shared_ptr<mem::aligned::vector<Worker>> others)
Parameters

others – pointer to the vector of all workers.

inline void steal_range(mem::aligned::vector<Worker> &workers)
Parameters

workers – vector of all workers.

inline bool all_done(mem::aligned::vector<Worker> const &workers)
Parameters

workers – vector of all workers.

inline Worker &find_victim(mem::aligned::vector<Worker> &workers)

targets the worker with the largest remaining range to minimize number of steal events.

Parameters

others – vector of all workers.

Public Members

mem::aligned::relaxed_atomic<State> state

worker state {pos, end}

Function f