forked from taskflow/taskflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple.cpp
27 lines (22 loc) · 1.18 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
// A simple example to capture the following task dependencies.
//
// TaskA---->TaskB---->TaskD
// TaskA---->TaskC---->TaskD
#include "taskflow.hpp" // the only include you need
int main(){
tf::Taskflow tf(std::thread::hardware_concurrency());
auto [A, B, C, D] = tf.silent_emplace(
[] () { std::cout << "TaskA\n"; }, // the taskflow graph
[] () { std::cout << "TaskB\n"; }, //
[] () { std::cout << "TaskC\n"; }, // +---+
[] () { std::cout << "TaskD\n"; } // +---->| B |-----+
); // | +---+ |
// +---+ +-v-+
A.precede(B); // B runs after A // | A | | D |
A.precede(C); // C runs after A // +---+ +-^-+
B.precede(D); // D runs after B // | +---+ |
C.precede(D); // C runs after D // +---->| C |-----+
// +---+
tf.wait_for_all(); // block until finished
return 0;
}