forked from taskflow/taskflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipeline.cpp
More file actions
60 lines (46 loc) · 1.12 KB
/
Copy pathpipeline.cpp
File metadata and controls
60 lines (46 loc) · 1.12 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// 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::Taskflow tf;
tf::Framework f;
std::mutex mtx;
auto [A, B, C] = f.emplace(
[&] () {
std::scoped_lock lock(mtx);
std::puts("TaskA");
},
[&] (auto &subflow) {
std::scoped_lock lock(mtx);
std::puts("TaskB");
subflow.emplace([&](){
std::scoped_lock lock(mtx);
std::puts("TaskB1");
});
subflow.emplace([&](){
std::scoped_lock lock(mtx);
std::puts("TaskB2");
});
subflow.detach();
},
[&] () {
std::scoped_lock lock(mtx);
std::puts("TaskC");
}
);
A.name("A");
B.name("B");
C.name("C");
// Linear
A.precede(B);
B.precede(C);
tf.pipeline_until(f, [iter = 3]() mutable {
std::cout << "iter = " << iter << std::endl;
return iter -- == 0; }, [](){}
).get();
//std::cout << f.dump() << std::endl;
//tf.wait_for_all(); // block until finished
return 0;
}