Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 481a00b

Browse files
Merge branch 'dev' of https://github.com/cpp-taskflow/cpp-taskflow into dev
2 parents 02e1af3 + 3380a5f commit 481a00b

File tree

6 files changed

+137
-84
lines changed

6 files changed

+137
-84
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ set_target_properties(taskflow_test_tmp PROPERTIES OUTPUT_NAME "taskflow")
260260
add_test(builder ${TF_UTEST_DIR}/taskflow -tc=Builder)
261261
add_test(creation ${TF_UTEST_DIR}/taskflow -tc=Creation)
262262
add_test(dispatch ${TF_UTEST_DIR}/taskflow -tc=Dispatch)
263-
add_test(multiple_runs ${TF_UTEST_DIR}/taskflow -tc=MultipleRuns)
263+
add_test(sequential_runs ${TF_UTEST_DIR}/taskflow -tc=SequentialRuns)
264+
add_test(parallel_runs ${TF_UTEST_DIR}/taskflow -tc=ParallelRuns)
264265
add_test(parallel_for ${TF_UTEST_DIR}/taskflow -tc=ParallelFor)
265266
add_test(parallel_for_idx ${TF_UTEST_DIR}/taskflow -tc=ParallelForOnIndex)
266267
add_test(reduce ${TF_UTEST_DIR}/taskflow -tc=Reduce)

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ The executor provides a rich set of methods to run a taskflow.
216216
You can run a taskflow one or multiple times, or until a stopping criteria is met.
217217
These methods are non-blocking and all return a [std::future][std::future]
218218
to let you query the execution status.
219+
All methods are *thread-safe*.
219220

220221
```cpp
221222
executor.run(taskflow); // run the taskflow once
@@ -527,7 +528,7 @@ tf::Task B = taskflow.emplace([] (tf::Subflow& subflow) {
527528

528529
A.precede(B);
529530

530-
executor.run(tf).get(); // run the taskflow
531+
executor.run(tf).wait(); // run the taskflow
531532
tf.dump(std::cout); // dump the graph including dynamic tasks
532533
```
533534

doxygen/cookbook/Chapter2.dox

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ tf::Executor executor2(4); // create an executor of 4 worker threads
3131
@endcode
3232

3333
An executor can be reused to execute multiple taskflows.
34-
In most workloads, you may need only one executor but multiple taskflows
35-
to represent parts of a parallel decomposition.
34+
In most workloads, you may need only one executor to run multiple taskflows
35+
where each taskflow represents a part of a parallel decomposition.
3636

3737
@section C2_ExecuteATaskflow Execute a Taskflow
3838

@@ -78,7 +78,7 @@ Debrief:
7878
@li Line 20 keeps running the taskflow until the predicate returns true
7979

8080
Issuing multiple runs on the same taskflow will automatically @em synchronize
81-
to a sequential chain of executions following the order of the run calls.
81+
to a sequential chain of executions in the order of run calls.
8282

8383
@code{.cpp}
8484
executor.run(taskflow); // execution 1

example/observer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
int main(){
66

7-
tf::Executor executor(0);
7+
tf::Executor executor;
88

99
// Create a taskflow of eight tasks
1010
tf::Taskflow taskflow;

taskflow/core/executor.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// 2019/08/03 - modified by Tsung-Wei Huang
2+
// - made executor thread-safe
3+
//
14
// 2019/07/26 - modified by Chun-Xun Lin
25
// - Combine explore_task & wait_for_task
36
// - Remove CAS operations
@@ -999,8 +1002,10 @@ std::future<void> Executor::run_until(Taskflow& f, P&& pred, C&& c) {
9991002

10001003
// Special case of predicate
10011004
if(std::invoke(pred)) {
1005+
std::promise<void> promise;
1006+
promise.set_value();
10021007
_decrement_topology_and_notify();
1003-
return std::async(std::launch::deferred, [](){});
1008+
return promise.get_future();
10041009
}
10051010

10061011
// Special case of zero workers requires:
@@ -1028,10 +1033,12 @@ std::future<void> Executor::run_until(Taskflow& f, P&& pred, C&& c) {
10281033
if(tpg._call != nullptr) {
10291034
std::invoke(tpg._call);
10301035
}
1036+
1037+
tpg._promise.set_value();
10311038

10321039
_decrement_topology_and_notify();
10331040

1034-
return std::async(std::launch::deferred, [](){});
1041+
return tpg._promise.get_future();
10351042
}
10361043

10371044
// Multi-threaded execution.

0 commit comments

Comments
 (0)