You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/classtf_1_1AsyncTask.html
+6-1Lines changed: 6 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -61,7 +61,12 @@ <h3>Contents</h3>
61
61
</li>
62
62
</ul>
63
63
</nav>
64
-
<p>An async-task is a lightweight handle that leverages <ahref="http://en.cppreference.com/w/cpp/memory/shared_ptr.html" class="m-doc-external">std::<wbr/>shared_ptr</a> to retain shared ownership of a dependent asynchronous task created by an executor (e.g., <ahref="classtf_1_1Executor.html#aee02b63d3a91ad5ca5a1c0e71f3e128f" class="m-doc">tf::<wbr/>Executor::<wbr/>dependent_async</a>). The purpose of shared ownership is to avoid potential ABA problem when creating asynchronous tasks with dependents that already vanished.</p>
64
+
<p>A <ahref="classtf_1_1AsyncTask.html" class="m-doc">tf::<wbr/>AsyncTask</a> is a lightweight handle that retains <em>shared</em> ownership of a dependent async task created by an executor. This shared ownership ensures that the async task remains alive when adding it to the dependency list of another async task, thus avoiding the classical <ahref="https://en.wikipedia.org/wiki/ABA_problem">ABA problem</a>.</p><preclass="m-code"><spanclass="c1">// main thread retains shared ownership of async task A</span>
<spanclass="c1">// task A remains alive (i.e., at least one ref count by the main thread) </span>
68
+
<spanclass="c1">// when being added to the dependency list of async task B</span>
69
+
<spanclass="n">tf</span><spanclass="o">::</span><spanclass="n">AsyncTask</span><spanclass="w"></span><spanclass="n">B</span><spanclass="w"></span><spanclass="o">=</span><spanclass="w"></span><spanclass="n">executor</span><spanclass="p">.</span><spanclass="n">silent_dependent_async</span><spanclass="p">([](){},</span><spanclass="w"></span><spanclass="n">A</span><spanclass="p">);</span></pre><p>Currently, <ahref="classtf_1_1AsyncTask.html" class="m-doc">tf::<wbr/>AsyncTask</a> is implemented based on C++ smart pointer <ahref="http://en.cppreference.com/w/cpp/memory/shared_ptr.html" class="m-doc-external">std::<wbr/>shared_ptr</a> and is considered cheap to copy or move as long as only a handful of objects own it. When a worker completes an async task, it will remove the task from the executor, decrementing the number of shared owners by one. If that counter reaches zero, the task is destroyed.</p>
0 commit comments