dispenso
A library for task parallelism
 
Loading...
Searching...
No Matches
dispenso::TaskSet Class Reference

#include <task_set.h>

Inherits TaskSetBase.

Public Member Functions

 TaskSet (ThreadPool &p, ParentCascadeCancel registerForParentCancel, ssize_t stealingLoadMultiplier=kDefaultStealingMultiplier)
 
 TaskSet (ThreadPool &p)
 
 TaskSet (ThreadPool &p, ssize_t stealingLoadMultiplier)
 
 TaskSet (TaskSet &&other)=delete
 
TaskSetoperator= (TaskSet &&other)=delete
 
template<typename F >
void schedule (F &&f)
 
template<typename F >
void schedule (F &&f, ForceQueuingTag fq)
 
DISPENSO_DLL_ACCESS bool wait ()
 
DISPENSO_DLL_ACCESS bool tryWait (size_t maxToExecute)
 
void cancel ()
 
bool canceled () const
 
 ~TaskSet ()
 

Detailed Description

TaskSet is an object that allows scheduling multiple functors to a thread pool, and allows to wait on that set of tasks. TaskSet supplies more efficient schedule/wait than ConcurrentTaskSet, but at the expense of only being usable from one thread at a time.

TaskSet is "thread-compatible". This means that you can safely use different TaskSet objects on different threads concurrently. Any given TaskSet object may only be used from a single thread, so no concurrent use of that object is allowed.

Definition at line 37 of file task_set.h.

Constructor & Destructor Documentation

◆ TaskSet() [1/3]

dispenso::TaskSet::TaskSet ( ThreadPool p,
ParentCascadeCancel  registerForParentCancel,
ssize_t  stealingLoadMultiplier = kDefaultStealingMultiplier 
)
inline

Construct a TaskSet with the given backing pool.

Parameters
poolThe backing pool for this TaskSet
stealingLoadMultiplierAn over-load factor. If this factor of load is reached by the underlying pool, scheduled tasks may run immediately in the calling thread.

Definition at line 46 of file task_set.h.

◆ TaskSet() [2/3]

dispenso::TaskSet::TaskSet ( ThreadPool p)
inline

Definition at line 53 of file task_set.h.

◆ TaskSet() [3/3]

dispenso::TaskSet::TaskSet ( ThreadPool p,
ssize_t  stealingLoadMultiplier 
)
inline

Definition at line 54 of file task_set.h.

◆ ~TaskSet()

dispenso::TaskSet::~TaskSet ( )
inline

Destroy the TaskSet, first waiting for all currently scheduled functors to finish execution.

Definition at line 147 of file task_set.h.

Member Function Documentation

◆ cancel()

void dispenso::TaskSet::cancel ( )
inline

Set the TaskSet to canceled state. No unexecuted tasks will execute once this is set. Already executing tasks may check canceled() status to exit early.

Definition at line 130 of file task_set.h.

◆ canceled()

bool dispenso::TaskSet::canceled ( ) const
inline

Check the canceled status of the TaskSet.

Returns
a boolean indicating whether or not the TaskSet has been canceled.

Definition at line 139 of file task_set.h.

◆ schedule() [1/2]

template<typename F >
void dispenso::TaskSet::schedule ( F &&  f)
inline

Schedule a functor for execution on the underlying pool. If the load on the underlying pool is high, immediate inline execution may occur on the current thread.

Parameters
fA functor matching signature void(). Best performance will come from passing lambdas, other concrete functors, or OnceFunction, but std::function or similarly type-erased objects will also work.
Note
If f can throw exceptions, then schedule may throw if the task is run inline. Otherwise, exceptions will be caught on the running thread and best-effort propagated to the ConcurrentTaskSet, where the first one from the set is rethrown in wait.

Definition at line 74 of file task_set.h.

◆ schedule() [2/2]

template<typename F >
void dispenso::TaskSet::schedule ( F &&  f,
ForceQueuingTag  fq 
)
inline

Schedule a functor for execution on the underlying pool.

Parameters
fA functor matching signature void(). Best performance will come from passing lambdas, other concrete functors, or OnceFunction, but std::function or similarly type-erased objects will also work.
Note
If f can throw exceptions, then exceptions will be caught on the running thread and best-effort propagated to the ConcurrentTaskSet, where the first one from the set is rethrown in wait.

Definition at line 97 of file task_set.h.

◆ tryWait()

bool dispenso::TaskSet::tryWait ( size_t  maxToExecute)

See if the currently scheduled functors can be completed while stealing and executing at most maxToExecute of them from the pool. If not used in conjunction with wait, there may be cases that tryWait must be called multiple times with maxToExecute &gt 0 to prevent livelock/deadlock. If exceptions have been propagated since the last call to wait or tryWait, tryWait will propagate the first of them.

Parameters
maxToExecuteThe maximum number of tasks to proactively execute on the current thread.
Returns
true if all currently scheduled functors have been completed prior to returning, and false otherwise. This includes returning false if the TaskSet was cancelled.

Definition at line 131 of file task_set.cpp.

◆ wait()

bool dispenso::TaskSet::wait ( )

Wait for all currently scheduled functors to finish execution. If exceptions are thrown during execution of the set of tasks, wait will propagate the first exception.

Returns
true if the TaskSet was canceled, false otherwise

Definition at line 114 of file task_set.cpp.


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