FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp-taskflow/examples/limited_concurrency.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
/
limited_concurrency.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
36 lines (27 loc) · 912 Bytes
Breadcrumbs
cpp-taskflow
/
examples
/
limited_concurrency.cpp
Copy path
File metadata and controls
36 lines (27 loc) · 912 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
32
33
34
35
36
//
A simple example with a semaphore constraint that only one task can
//
execute at a time.
#
include
<
taskflow/taskflow.hpp
>
void
sl
() {
std::this_thread::sleep_for
(
std::chrono::seconds
(
1
));
}
int
main
() {
tf::Executor
executor
(
4
);
tf::Taskflow taskflow;
//
define a critical region of 1 worker
tf::Semaphore
semaphore
(
1
);
//
create give tasks in taskflow
std::vector<tf::Task> tasks {
taskflow.
emplace
([](){
sl
(); std::cout <<
"
A
"
<< std::endl; }),
taskflow.
emplace
([](){
sl
(); std::cout <<
"
B
"
<< std::endl; }),
taskflow.
emplace
([](){
sl
(); std::cout <<
"
C
"
<< std::endl; }),
taskflow.
emplace
([](){
sl
(); std::cout <<
"
D
"
<< std::endl; }),
taskflow.
emplace
([](){
sl
(); std::cout <<
"
E
"
<< std::endl; })
};
for
(
auto
& task : tasks) {
task.
acquire
(semaphore);
task.
release
(semaphore);
}
executor.
run
(taskflow);
executor.
wait_for_all
();
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL