-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflow_graph.cpp
More file actions
64 lines (54 loc) · 1.32 KB
/
Copy pathflow_graph.cpp
File metadata and controls
64 lines (54 loc) · 1.32 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
58
59
60
61
62
63
64
//
// Created by blackgeorge on 8/16/19.
//
#include <cstdio>
#include <iostream>
#include <chrono>
#include <thread>
#include <tbb/task_group.h>
#include "tbb/flow_graph.h"
using namespace tbb::flow;
struct body {
std::string my_name;
explicit body(const char *name) : my_name(name) {}
void operator()(continue_msg) const {
printf("%s\n", my_name.c_str());
}
};
void print_num(int n)
{
std::this_thread::sleep_for(std::chrono::seconds(n));
std::cout << "Look: " << n << std::endl;
}
int main()
{
graph g;
broadcast_node< continue_msg > start(g);
continue_node<continue_msg> a(g, body("A"));
continue_node<continue_msg> b(g, body("B"));
continue_node<continue_msg> c(g, body("C"));
continue_node<continue_msg> d(g, body("D"));
continue_node<continue_msg> e(g, body("E"));
make_edge(start, a);
make_edge(start, b);
make_edge(a, c);
make_edge(b, c);
make_edge(c, d);
make_edge(a, e);
// for (int i = 0; i < 3; ++i) {
// start.try_put(continue_msg());
// g.wait_for_all();
// }
tbb::task_group tg;
for (auto i = 0; i < 4; ++i) {
tg.run(
[=]
{
if (i == 0) return 1;
print_num(i);
}
);
}
tg.wait();
return 0;
}