FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp-taskflow/examples/condition.cpp at master · OSHO-1989/cpp-taskflow · GitHub
OSHO-1989
/
cpp-taskflow
Public
forked from
taskflow/taskflow
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp-taskflow
/
examples
/
condition.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
74 lines (54 loc) · 1.39 KB
Breadcrumbs
cpp-taskflow
/
examples
/
condition.cpp
Copy path
File metadata and controls
74 lines (54 loc) · 1.39 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
65
66
67
//
The example creates the following cyclic graph:
//
//
A
//
|
//
v
//
B<---|
//
| |
//
v |
//
C----|
//
|
//
v
//
D
//
//
- A is a task that initializes a counter to zero
//
- B is a task that increments the counter
//
- C is a condition task that loops around B until the counter
//
reaches a breaking number
//
- D is a task that wraps up the result
#
include
<
taskflow/taskflow.hpp
>
int
main
() {
tf::Executor executor;
tf::Taskflow
taskflow
(
"
Conditional Tasking Demo
"
);
int
counter;
auto
A = taskflow.
emplace
([&](){
std::cout <<
"
initializes the counter to zero
\n
"
;
counter =
0
;
}).
name
(
"
A
"
);
auto
B = taskflow.
emplace
([&](){
std::cout <<
"
loops to increment the counter
\n
"
;
counter++;
}).
name
(
"
B
"
);
auto
C = taskflow.
emplace
([&](){
std::cout <<
"
counter is
"
<< counter <<
"
->
"
;
if
(counter !=
5
) {
std::cout <<
"
loops again (goes to B)
\n
"
;
return
0
;
}
std::cout <<
"
breaks the loop (goes to D)
\n
"
;
return
1
;
}).
name
(
"
C
"
);
auto
D = taskflow.
emplace
([&](){
std::cout <<
"
done with counter equal to
"
<< counter <<
'
\n
'
;
}).
name
(
"
D
"
);
A.
precede
(B);
B.
precede
(C);
C.
precede
(B);
C.
precede
(D);
//
visualizes the taskflow
taskflow.
dump
(std::cout);
//
executes the taskflow
executor.
run
(taskflow).
wait
();
assert
(counter ==
5
);
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL