docs/classtf_1_1Future.html
| | Taskflow: A General-purpose Task-parallel Programming System |
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
tf::Future< T > Class Template Reference
class to access the result of an execution More...
#include <taskflow/core/taskflow.hpp>
Inheritance diagram for tf::Future< T >:
[Embedded content](classtf_1_1Future inherit graph.svg)
[legend]
Collaboration diagram for tf::Future< T >:
[Embedded content](classtf_1_1Future coll graph.svg)
[legend]
|
|
| | Future ()=default |
| | default constructor
|
| |
| | Future (const Future &)=delete |
| | disabled copy constructor
|
| |
| | Future (Future &&)=default |
| | default move constructor
|
| |
| | Future (std::future< T > &&) |
| | constructs *this from a std::future
|
| |
| Future & | operator= (const Future &)=delete |
| | disabled copy assignment
|
| |
| Future & | operator= (Future &&)=default |
| | default move assignment
|
| |
| bool | cancel () |
| | cancels the execution of the running taskflow associated with this future object
|
| |
|
| | class | Executor | | | | class | Subflow | | | | class | Runtime | | |
template<typename T>
class tf::Future< T >
class to access the result of an execution
tf::Future is a derived class from std::future that will eventually hold the execution result of a submitted taskflow (tf::Executor::run series). In addition to the base methods inherited from std::future, you can call tf::Future::cancel to cancel the execution of the running taskflow associated with this future object. The following example cancels a submission of a taskflow that contains 1000 tasks each running one second.
tf::Executor executor;
tf::Taskflow taskflow;
for(int i=0; i<1000; i++) {
taskflow.emplace({
std::this_thread::sleep_for(std::chrono::seconds(1));
});
}
// submit the taskflow
tf::Future fu = executor.run(taskflow);
// request to cancel the submitted execution above
fu.cancel();
// wait until the cancellation finishes
fu.get();
class to create an executor
Definition executor.hpp:62
tf::Future< void > run(Taskflow &taskflow)
runs a taskflow once
Task emplace(C &&callable)
creates a static task
Definition flow_builder.hpp:1571
class to access the result of an execution
Definition taskflow.hpp:630
bool cancel()
cancels the execution of the running taskflow associated with this future object
Definition taskflow.hpp:721
class to create a taskflow object
Definition taskflow.hpp:64
template<typename T>
| bool tf::Future< T >::cancel | ( | | ) | |
cancels the execution of the running taskflow associated with this future object
Returnstrue if the execution can be cancelled or false if the execution has already completed
When you request a cancellation, the executor will stop scheduling any tasks onwards. Tasks that are already running will continue to finish as their executions are non-preemptive. You can call tf::Future::wait to wait for the cancellation to complete.
// create a taskflow of four tasks and submit it to an executor
taskflow.emplace(
);
auto future = executor.run(taskflow);
// cancel the execution of the taskflow and wait until it finishes all running tasks
future.cancel();
future.wait();
In the above example, we submit a taskflow of four tasks to the executor and then issue a cancellation to stop its execution. Since the cancellation is non-deterministic with the executor runtime, we may still see some tasks complete their executions or none.
The documentation for this class was generated from the following file:
taskflow/core/taskflow.hpp
Maintained by Dr. Tsung-Wei Huang — Generated by 1.13.1