FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp-taskflow/examples/corun.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
/
corun.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
31 lines (23 loc) · 708 Bytes
Breadcrumbs
cpp-taskflow
/
examples
/
corun.cpp
Copy path
File metadata and controls
31 lines (23 loc) · 708 Bytes
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
//
This example demonstrates how to use the corun method from a running worker
//
of an executor to avoid deadlock.
#
include
<
taskflow/taskflow.hpp
>
int
main
(){
const
size_t
N =
100
;
const
size_t
T =
1000
;
//
create an executor and a taskflow
tf::Executor
executor
(
2
);
tf::Taskflow taskflow;
std::array<tf::Taskflow, N> taskflows;
std::atomic<
size_t
> counter{
0
};
for
(
size_t
n=
0
; n<N; n++) {
for
(
size_t
i=
0
; i<T; i++) {
taskflows[n].
emplace
([&](){ counter++; });
}
taskflow.
emplace
([&executor, &tf=taskflows[n]](){
executor.
corun
(tf);
//
executor.run(tf).wait(); <-- can result in deadlock
});
}
executor.
run
(taskflow).
wait
();
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL