forked from taskflow/taskflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple.cpp
30 lines (23 loc) · 1.14 KB
/
simple.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// A simple example to capture the following task dependencies.
//
// TaskA---->TaskB---->TaskD
// TaskA---->TaskC---->TaskD
#include <taskflow/taskflow.hpp> // the only include you need
int main(){
tf::Executor executor;
tf::Taskflow taskflow("simple");
auto A = taskflow.emplace([]() { std::cout << "TaskA\n"; });
auto B = taskflow.emplace([]() { std::cout << "TaskB\n"; });
auto C = taskflow.emplace([]() { std::cout << "TaskC\n"; });
auto D = taskflow.emplace([]() { std::cout << "TaskD\n"; });
A.precede(B); // B runs after A // +---+
A.precede(C); // C runs after A // +---->| B |-----+
B.precede(D); // D runs after B // | +---+ |
C.precede(D); // D runs after C // +---+ +-v-+
// | A | | D |
// +---+ +-^-+
executor.run(taskflow).wait(); // | +---+ |
// +---->| C |-----+
// +---+
return 0;
}