Taskflow  3.2.0-Master-Branch
Loading...
Searching...
No Matches
tf::Runtime Class Reference

class to create a runtime object used by a runtime task More...

#include <graph.hpp>

Public Member Functions

Executorexecutor ()
 obtains the running executor
 
void schedule (Task task)
 schedules an active task immediately to the worker's queue
 
template<typename C >
void run (C &&)
 runs a task callable synchronously
 

Friends

class Executor
 

Detailed Description

class to create a runtime object used by a runtime task

A runtime object is used by a runtime task for users to interact with the scheduling runtime, such as scheduling an active task and spawning a subflow.

taskflow.emplace([](tf::Runtime& rt){
rt.run([](tf::Subflow& sf){
tf::Task A = sf.emplace([](){});
tf::Task B = sf.emplace([](){});
A.precede(B);
});
});
Task emplace(C &&callable)
creates a static task
Definition flow_builder.hpp:742
class to create a runtime object used by a runtime task
Definition graph.hpp:150
void run(C &&)
runs a task callable synchronously
Definition executor.hpp:1963
class to construct a subflow graph from the execution of a dynamic task
Definition flow_builder.hpp:889
class to create a task handle over a node in a taskflow graph
Definition task.hpp:187
Task & precede(Ts &&... tasks)
adds precedence links from this to other tasks
Definition task.hpp:420

A runtime task is associated with an executor and a worker that runs the runtime task.

Member Function Documentation

◆ executor()

Executor & tf::Runtime::executor ( )
inline

obtains the running executor

The running executor of a runtime task is the executor that runs the parent taskflow of that runtime task.

tf::Taskflow taskflow;
taskflow.emplace([&](tf::Runtime& rt){
assert(&(rt.executor()) == &executor);
});
executor.run(taskflow).wait();
class to create an executor for running a taskflow graph
Definition executor.hpp:50
tf::Future< void > run(Taskflow &taskflow)
runs a taskflow once
Definition executor.hpp:1573
Executor & executor()
obtains the running executor
Definition graph.hpp:233
class to create a taskflow object
Definition core/taskflow.hpp:73

◆ schedule()

void tf::Runtime::schedule ( Task  task)
inline

schedules an active task immediately to the worker's queue

Parameters
taskthe given active task to schedule immediately

This member function immediately schedules an active task to the task queue of the associated worker in the runtime task. An active task is a task in a running taskflow. The task may or may not be running, and scheduling that task will immediately put the task into the task queue of the worker that is running the runtime task. Consider the following example:

tf::Task A, B, C, D;
std::tie(A, B, C, D) = taskflow.emplace(
[] () { return 0; },
[&C] (tf::Runtime& rt) { // C must be captured by reference
std::cout << "B\n";
rt.schedule(C);
},
[] () { std::cout << "C\n"; },
[] () { std::cout << "D\n"; }
);
A.precede(B, C, D);
executor.run(taskflow).wait();
T tie(T... args)

The executor will first run the condition task A which returns 0 to inform the scheduler to go to the runtime task B. During the execution of B, it directly schedules task C without going through the normal taskflow graph scheduling process. At this moment, task C is active because its parent taskflow is running. When the taskflow finishes, we will see both B and C in the output.


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