|
Cpp-Taskflow
2.3.0
|
The executor class to run a taskflow graph. More...
#include <executor.hpp>
Public Member Functions | |
| Executor (unsigned n=std::thread::hardware_concurrency()) | |
| constructs the executor with N worker threads | |
| ~Executor () | |
| destructs the executor | |
| std::future< void > | run (Taskflow &taskflow) |
| runs the taskflow once More... | |
| template<typename C > | |
| std::future< void > | run (Taskflow &taskflow, C &&callable) |
| runs the taskflow once and invoke a callback upon completion More... | |
| std::future< void > | run_n (Taskflow &taskflow, size_t N) |
| runs the taskflow for N times More... | |
| template<typename C > | |
| std::future< void > | run_n (Taskflow &taskflow, size_t N, C &&callable) |
| runs the taskflow for N times and then invokes a callback More... | |
| template<typename P > | |
| std::future< void > | run_until (Taskflow &taskflow, P &&pred) |
| runs the taskflow multiple times until the predicate becomes true and then invokes a callback More... | |
| template<typename P , typename C > | |
| std::future< void > | run_until (Taskflow &taskflow, P &&pred, C &&callable) |
| runs the taskflow multiple times until the predicate becomes true and then invokes the callback More... | |
| void | wait_for_all () |
| wait for all pending graphs to complete | |
| size_t | num_workers () const |
| queries the number of worker threads (can be zero) More... | |
| template<typename Observer , typename... Args> | |
| Observer * | make_observer (Args &&... args) |
| constructs an observer to inspect the activities of worker threads More... | |
| void | remove_observer () |
| removes the associated observer | |
| int | this_worker_id () const |
| queries the id of the caller thread in this executor More... | |
The executor class to run a taskflow graph.
An executor object manages a set of worker threads and implements an efficient work-stealing scheduling algorithm to run a task graph.
| Observer * tf::Executor::make_observer | ( | Args &&... | args | ) |
constructs an observer to inspect the activities of worker threads
Each executor manages at most one observer at a time through std::unique_ptr. Createing multiple observers will only keep the lastest one.
| Observer | observer type derived from tf::ExecutorObserverInterface |
| ArgsT... | argument parameter pack |
| args | arguments to forward to the constructor of the observer |
|
inline |
queries the number of worker threads (can be zero)
|
inline |
runs the taskflow once
| taskflow | a tf::Taskflow object |
| std::future< void > tf::Executor::run | ( | Taskflow & | taskflow, |
| C && | callable | ||
| ) |
runs the taskflow once and invoke a callback upon completion
| taskflow | a tf::Taskflow object |
| callable | a callable object to be invoked after this run |
|
inline |
runs the taskflow for N times
| taskflow | a tf::Taskflow object |
| N | number of runs |
| std::future< void > tf::Executor::run_n | ( | Taskflow & | taskflow, |
| size_t | N, | ||
| C && | callable | ||
| ) |
runs the taskflow for N times and then invokes a callback
| taskflow | a tf::Taskflow |
| N | number of runs |
| callable | a callable object to be invoked after this run |
| std::future< void > tf::Executor::run_until | ( | Taskflow & | taskflow, |
| P && | pred | ||
| ) |
runs the taskflow multiple times until the predicate becomes true and then invokes a callback
| taskflow | a tf::Taskflow |
| pred | a boolean predicate to return true for stop |
| std::future< void > tf::Executor::run_until | ( | Taskflow & | taskflow, |
| P && | pred, | ||
| C && | callable | ||
| ) |
runs the taskflow multiple times until the predicate becomes true and then invokes the callback
| taskflow | a tf::Taskflow |
| pred | a boolean predicate to return true for stop |
| callable | a callable object to be invoked after this run |
|
inline |
queries the id of the caller thread in this executor
Each worker has an unique id from 0 to N-1 exclusive to the associated executor. If the caller thread does not belong to the executor, -1 is returned.