FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp-taskflow/examples/cancel.cpp at master · feiyunwill/cpp-taskflow · GitHub
feiyunwill
/
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
/
cancel.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
39 lines (28 loc) · 1.01 KB
Breadcrumbs
cpp-taskflow
/
examples
/
cancel.cpp
Copy path
File metadata and controls
39 lines (28 loc) · 1.01 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
//
The program demonstrates how to cancel a submitted taskflow
//
graph and wait until the cancellation completes.
#
include
<
taskflow/taskflow.hpp
>
int
main
() {
tf::Executor executor;
tf::Taskflow
taskflow
(
"
cancel
"
);
//
We create a taskflow graph of 1000 tasks each of 1 second.
//
Ideally, the taskflow completes in 1000/P seconds, where P
//
is the number of workers.
for
(
int
i=
0
; i<
1000
; i++) {
taskflow.
emplace
([](){
std::this_thread::sleep_for
(
std::chrono::seconds
(
1
));
});
}
//
submit the taskflow
auto
beg =
std::chrono::steady_clock::now
();
tf::Future fu = executor.
run
(taskflow);
//
submit a cancel request to cancel all 1000 tasks.
fu.
cancel
();
//
wait until the cancellation finishes
fu.
get
();
auto
end =
std::chrono::steady_clock::now
();
//
the duration should be much less than 1000 seconds
std::cout <<
"
taskflow completes in
"
<< std::chrono::duration_cast<std::chrono::milliseconds>(end-beg).
count
()
<<
"
milliseconds
\n
"
;
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL