#include <task_set.h>
Inherits TaskSetBase.
Public Member Functions | |
ConcurrentTaskSet (ThreadPool &pool, ParentCascadeCancel registerForParentCancel, ssize_t stealingLoadMultiplier=kDefaultStealingMultiplier) | |
ConcurrentTaskSet (ThreadPool &p) | |
ConcurrentTaskSet (ThreadPool &p, ssize_t stealingLoadMultiplier) | |
ConcurrentTaskSet (ConcurrentTaskSet &&other)=delete | |
ConcurrentTaskSet & | operator= (ConcurrentTaskSet &&other)=delete |
template<typename F > | |
void | schedule (F &&f, bool skipRecheck=false) |
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 |
~ConcurrentTaskSet () | |
ConcurrentTaskSet
fulfills the same API as TaskSet
with one minor difference: It may be used to schedule tasks concurrently from multiple threads (see more below). It is an object that allows scheduling multiple function-like objects to a thread pool, and allows to wait on that set of tasks.
ConcurrentTaskSet
is "thread-compatible". This means that you can safely use different ConcurrentTaskSet
objects on different threads concurrently. ConcurrentTaskSet
also allows multiple threads to concurrently schedule against it. It is an error to call wait() concurrently with schedule() on the same ConcurrentTaskSet
.
Definition at line 173 of file task_set.h.
|
inline |
Construct a ConcurrentTaskSet with the given backing pool.
pool | The backing pool for this ConcurrentTaskSet |
stealingLoadMultiplier | An 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 182 of file task_set.h.
|
inline |
Definition at line 188 of file task_set.h.
|
inline |
Definition at line 190 of file task_set.h.
|
inline |
Destroy the ConcurrentTaskSet, first waiting for all currently scheduled functors to finish execution.
Definition at line 284 of file task_set.h.
|
inline |
Set the ConcurrentTaskSet 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 267 of file task_set.h.
|
inline |
Check the canceled status of the ConcurrentTaskSet.
Definition at line 276 of file task_set.h.
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.
f | A 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. |
skipRecheck | A poweruser knob that says that if we don't have enough outstanding tasks to immediately work steal, we should bypass the similar check in the ThreadPool. |
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 213 of file task_set.h.
|
inline |
Schedule a functor for execution on the underlying pool.
f | A 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. |
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 236 of file task_set.h.
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 > 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.
maxToExecute | The maximum number of tasks to proactively execute on the current thread. |
true
if all currently scheduled functors have been completed prior to returning, and false
otherwise (including cancelled cases). Definition at line 93 of file task_set.cpp.
bool dispenso::ConcurrentTaskSet::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.
Definition at line 76 of file task_set.cpp.