@@ -3,7 +3,7 @@ namespace tf {
33/** @page chapter1 C1: Understand the %Task
44
55In this chapter, we demonstrate the basic construct of
6- a task dependency graph - tf:: Task.
6+ a task dependency graph - Task.
77
88@section WhatIsATask What is a Task?
99
@@ -17,30 +17,28 @@ Taskflow::silent_emplace, and
1717Taskflow::emplace to create a task.
1818
1919@code{.cpp}
20- 1: tf::Taskflow tf;
21- 2: auto A = tf.placeholder();
22- 3: auto B = tf.silent_emplace([] () {});
23- 4: auto [C, FuC] = tf.emplace([] () { return 1; });
20+ 1: auto A = taskflow.placeholder();
21+ 2: auto B = taskflow.silent_emplace([] () {});
22+ 3: auto [C, FuC] = taskflow.emplace([] () { return 1; });
2423@endcode
2524
2625Debrief:
27- @li Line 1 creates a taskflow object
28- @li Line 2 creates an empty task
29- @li Line 3 creates a task from a given callable object and returns a task handle
30- @li Line 4 creates a task from a given callable object and returns, in addition to a task handle, a @std_future object to access the result
26+ @li Line 1 creates an empty task
27+ @li Line 2 creates a task from a given callable object and returns a task handle
28+ @li Line 3 creates a task from a given callable object and returns, in addition to a task handle, a @std_future object to access the result
3129
3230Each time you create a task, including an empty one,
3331the taskflow object adds a node to the present graph
34- and returns a task handle of type tf:: Task.
32+ and returns a task handle of type Task.
3533A task handle is a lightweight object
3634that wraps up a particular node in a graph
3735and provides a set of methods for you to assign different attributes to the task
3836such as adding dependencies, naming, and assigning a new work.
3937
4038@code{.cpp}
41- 1: tf::Taskflow tf ;
42- 2: auto A = tf .silent_emplace([] () { std::cout << "create a task A\n"; });
43- 3: auto B = tf .silent_emplace([] () { std::cout << "create a task B\n"; });
39+ 1: tf::Taskflow taskflow ;
40+ 2: auto A = taskflow .silent_emplace([] () { std::cout << "create a task A\n"; });
41+ 3: auto B = taskflow .silent_emplace([] () { std::cout << "create a task B\n"; });
4442 4:
4543 5: A.name("TaskA");
4644 6: A.work([] () { std::cout << "reassign A to a new task\n"; });
@@ -74,9 +72,8 @@ the associated task finishes.
7472This is particularly useful when you would like to pass data between tasks.
7573
7674@code{.cpp}
77- tf::Taskflow tf;
78- auto [A, FuA] = tf.emplace([](){ return 1; });
79- tf.wait_for_all();
75+ auto [A, FuA] = taskflow.emplace([](){ return 1; });
76+ taskflow.wait_for_all();
8077std::cout << FuA.get() << std::endl; // 1
8178@endcode
8279
@@ -86,10 +83,9 @@ The execution does not start until you dispatch the graph.
8683For example, the following code will block and never finish:
8784
8885@code{.cpp}
89- tf::Taskflow tf;
90- auto [A, FuA] = tf.emplace([](){ return 1; });
86+ auto [A, FuA] = taskflow.emplace([](){ return 1; });
9187std::cout << FuA.get() << std::endl; // block
92- tf .wait_for_all(); // never enter this line
88+ taskflow .wait_for_all(); // never enter this line
9389@endcode
9490
9591@section CreateMultipleTasksAtOneTime Create Multiple Tasks at One Time
@@ -100,7 +96,7 @@ Both Taskflow::silent_emplace and Taskflow::emplace can accept arbitrary numbers
10096and create multiple tasks at one time.
10197
10298@code{.cpp}
103- auto [A, B, C] = tf .silent_emplace( // create three tasks in one call
99+ auto [A, B, C] = taskflow .silent_emplace( // create three tasks in one call
104100 [](){ std::cout << "Task A\n"; },
105101 [](){ std::cout << "Task B\n"; },
106102 [](){ std::cout << "Task C\n"; }
@@ -129,36 +125,36 @@ task dependency graphs.
129125 2:
130126 3: int main() {
131127 4:
132- 5: tf::Taskflow tf ;
128+ 5: tf::Taskflow taskflow ;
133129 6:
134130 7: // create a task dependency graph
135131 8: std::array<tf::Task, 4> tasks {
136- 9: tf .silent_emplace([] () { std::cout << "Task A\n"; }),
137- 10: tf .silent_emplace([] () { std::cout << "Task B\n"; }),
138- 11: tf .silent_emplace([] () { std::cout << "Task C\n"; }),
139- 12: tf .silent_emplace([] () { std::cout << "Task D\n"; })
132+ 9: taskflow .silent_emplace([] () { std::cout << "Task A\n"; }),
133+ 10: taskflow .silent_emplace([] () { std::cout << "Task B\n"; }),
134+ 11: taskflow .silent_emplace([] () { std::cout << "Task C\n"; }),
135+ 12: taskflow .silent_emplace([] () { std::cout << "Task D\n"; })
14013613: };
14113714:
14213815: tasks[0].precede(tasks[1]);
14313916: tasks[0].precede(tasks[2]);
14414017: tasks[1].precede(tasks[3]);
14514118: tasks[2].precede(tasks[3]);
14614219:
147- 20: tf .wait_for_all();
143+ 20: taskflow .wait_for_all();
14814421:
14914522: // create another task dependency graph
15014623: tasks = {
151- 24: tf .silent_emplace([] () { std::cout << "New Task A\n"; }),
152- 25: tf .silent_emplace([] () { std::cout << "New Task B\n"; }),
153- 26: tf .silent_emplace([] () { std::cout << "New Task C\n"; }),
154- 27: tf .silent_emplace([] () { std::cout << "New Task D\n"; })
147+ 24: taskflow .silent_emplace([] () { std::cout << "New Task A\n"; }),
148+ 25: taskflow .silent_emplace([] () { std::cout << "New Task B\n"; }),
149+ 26: taskflow .silent_emplace([] () { std::cout << "New Task C\n"; }),
150+ 27: taskflow .silent_emplace([] () { std::cout << "New Task D\n"; })
15515128: };
15615229:
15715330: tasks[3].precede(tasks[2]);
15815431: tasks[2].precede(tasks[1]);
15915532: tasks[1].precede(tasks[0]);
16015633:
161- 34: tf .wait_for_all();
157+ 34: taskflow .wait_for_all();
16215835:
16315936: return 0;
16416037: }
@@ -189,11 +185,11 @@ the task handler.
189185 2:
190186 3: int main() {
191187 4:
192- 5: tf::Taskflow tf ;
188+ 5: tf::Taskflow taskflow ;
193189 6:
194190 7: std::vector<tf::Task> tasks = {
195- 8: tf .placeholder(), // create a task with no work
196- 9: tf .placeholder() // create a task with no work
191+ 8: taskflow .placeholder(), // create a task with no work
192+ 9: taskflow .placeholder() // create a task with no work
19719310: };
19819411:
19919512: tasks[0].name("This is Task 0");
@@ -206,12 +202,12 @@ the task handler.
20620219: << "num_successors=" << task.num_successors() << '\n';
20720320: }
20820421:
209- 22: tf .dump(std::cout); // dump the taskflow graph
205+ 22: taskflow .dump(std::cout); // dump the taskflow graph
21020623:
21120724: tasks[0].work([](){ std::cout << "got a new work!\n"; });
21220825: tasks[1].work([](){ std::cout << "got a new work!\n"; });
21320926:
214- 27: tf .wait_for_all();
210+ 27: taskflow .wait_for_all();
21521128:
21621229: return 0;
21721330: }
0 commit comments