Skip to content

Commit d920a46

Browse files
author
TSUNG-WEI HUANG
committed
merge pull
1 parent f941459 commit d920a46

11 files changed

+60
-16
lines changed

docs/ExceptionHandling.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ <h3>Contents</h3>
5656
<li><a href="#CatchAnExceptionFromASubflow">Catch an Exception from a Subflow</a></li>
5757
<li><a href="#CatchAnExceptionFromAnAsyncTask">Catch an Exception from an Async Task</a></li>
5858
<li><a href="#CatchAnExceptionFromACorunLoop">Catch an Exception from a Corun Loop</a></li>
59+
<li><a href="#TurnOffExceptionHandling">Turn Off Exception Handling</a></li>
5960
</ul>
6061
</nav>
6162
<p>This chapters discusses how to handle exceptions from a submitted taskflow so you can properly catch or propagate exceptions in your workload.</p><section id="CatchAnExceptionFromARunningTaskflow"><h2><a href="#CatchAnExceptionFromARunningTaskflow">Catch an Exception from a Running Taskflow</a></h2><p>When a task throws an exception, the executor will store that exception in the shared state referenced by the <a href="classtf_1_1Future.html" class="m-doc">tf::<wbr />Future</a> handle. You can catch that exception via calling the <code>get</code> method:</p><pre class="m-code"><span class="n">tf</span><span class="o">::</span><span class="n">Executor</span><span class="w"> </span><span class="n">executor</span><span class="p">;</span>
@@ -220,7 +221,7 @@ <h3>Contents</h3>
220221
<span class="p">}</span>
221222
<span class="k">catch</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">runtime_error</span><span class="o">&amp;</span><span class="w"> </span><span class="n">re</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
222223
<span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">cout</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">re</span><span class="p">.</span><span class="n">what</span><span class="p">()</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>
223-
<span class="p">}</span></pre><p>For the above example, if the exception is not caught with <a href="classtf_1_1Runtime.html#a1c772e90614302024cfa52fa86d75cac" class="m-doc">tf::<wbr />Runtime::<wbr />corun</a>, it will be propagated to its parent task, which is the <a href="classtf_1_1Runtime.html" class="m-doc">tf::<wbr />Runtime</a> object <code>rt</code> in this case. Then, the exception will be propagated to <code>taskflow2</code>.</p></section>
224+
<span class="p">}</span></pre><p>For the above example, if the exception is not caught with <a href="classtf_1_1Runtime.html#a1c772e90614302024cfa52fa86d75cac" class="m-doc">tf::<wbr />Runtime::<wbr />corun</a>, it will be propagated to its parent task, which is the <a href="classtf_1_1Runtime.html" class="m-doc">tf::<wbr />Runtime</a> object <code>rt</code> in this case. Then, the exception will be propagated to <code>taskflow2</code>.</p></section><section id="TurnOffExceptionHandling"><h2><a href="#TurnOffExceptionHandling">Turn Off Exception Handling</a></h2><p>In some applications, exception handling may not be desirable due to performance concerns, coding style preferences, or platform constraints. Taskflow allows you to disable exception handling entirely at compile time. To do this, simply define the macro <code>TF_DISABLE_EXCEPTION_HANDLING</code> when compiling your program:</p><pre class="m-code"><span class="o">~</span><span class="n">$</span><span class="w"> </span><span class="n">g</span><span class="o">++</span><span class="w"> </span><span class="o">-</span><span class="n">DTF_DISABLE_EXCEPTION_HANDLING</span><span class="w"> </span><span class="n">your_taskflow_prog</span><span class="p">.</span><span class="n">cpp</span></pre><p>Disabling exception handling removes all try-catch blocks from the Taskflow runtime, resulting in a leaner binary and potentially faster execution. However, please note that this also means Taskflow will not catch or report runtime exceptions.</p><aside class="m-note m-warning"><h4>Attention</h4><p>Disabling exception handling means that Taskflow will not catch or report runtime exceptions. Any exception thrown during execution will propagate unchecked and may cause your program to behave abnormally. Use this option only if you are confident that your application does not rely on exception safety.</p></aside></section>
224225
</div>
225226
</div>
226227
</div>

docs/contributors.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/release-3-11-0.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ <h3>Contents</h3>
6868
<li><a href="#release-3-11-0_miscellaneous_items">Miscellaneous Items</a></li>
6969
</ul>
7070
</nav>
71-
<p>Taskflow 3.11.0 is the newest developing line to new features and improvements we continue to support. It is also where this documentation is generated. Many things are considered <em>experimental</em> and may change or break from time to time. While it may be difficult to be keep all things consistent when introducing new features, we continue to try our best to ensure backward compatibility.</p><section id="release-3-11-0_download"><h2><a href="#release-3-11-0_download">Download</a></h2><p>To download the newest version of Taskflow, please clone the master branch from <a href="https://github.com/taskflow/taskflow">Taskflow&#x27;s GitHub</a>.</p></section><section id="release-3-11-0_system_requirements"><h2><a href="#release-3-11-0_system_requirements">System Requirements</a></h2><p>To use Taskflow v3.11.0, you need a compiler that supports C++17:</p><ul><li>GNU C++ Compiler at least v8.4 with -std=c++17</li><li>Clang C++ Compiler at least v6.0 with -std=c++17</li><li>Microsoft Visual Studio at least v19.27 with /std:c++17</li><li>Apple Clang Xcode Version at least v12.0 with -std=c++17</li><li>Nvidia CUDA Toolkit and Compiler (nvcc) at least v11.1 with -std=c++17</li><li>Intel C++ Compiler at least v19.0.1 with -std=c++17</li><li>Intel DPC++ Clang Compiler at least v13.0.0 with -std=c++17</li></ul><p>Taskflow works on Linux, Windows, and Mac OS X.</p><aside class="m-note m-warning"><h4>Attention</h4><p>Although Taskflow supports primarily C++17, you can enable C++20 compilation through <code>-std=c++20</code> to achieve better performance due to new C++20 features.</p></aside></section><section id="release-3-11-0_summary"><h2><a href="#release-3-11-0_summary">Release Summary</a></h2></section><section id="release-3-11-0_new_features"><h2><a href="#release-3-11-0_new_features">New Features</a></h2><section id="release-3-11-0_taskflow_core"><h3><a href="#release-3-11-0_taskflow_core">Taskflow Core</a></h3><ul><li>added five benchmarks to showcase the capability of <a href="classtf_1_1Runtime.html" class="m-doc">tf::<wbr />Runtime</a><ul><li>fibonacci</li><li>skynet</li><li>integrate</li><li>nqueens</li><li>primes</li></ul></li></ul></section><section id="release-3-11-0_utilities"><h3><a href="#release-3-11-0_utilities">Utilities</a></h3></section></section><section id="release-3-11-0_bug_fixes"><h2><a href="#release-3-11-0_bug_fixes">Bug Fixes</a></h2></section><section id="release-3-11-0_breaking_changes"><h2><a href="#release-3-11-0_breaking_changes">Breaking Changes</a></h2></section><section id="release-3-11-0_documentation"><h2><a href="#release-3-11-0_documentation">Documentation</a></h2></section><section id="release-3-11-0_miscellaneous_items"><h2><a href="#release-3-11-0_miscellaneous_items">Miscellaneous Items</a></h2><p>If you are interested in collaborating with us on applying Taskflow to your projects, please feel free to reach out to <a href="https://tsung-wei-huang.github.io/">Dr. Tsung-Wei Huang</a>!</p></section>
71+
<p>Taskflow 3.11.0 is the newest developing line to new features and improvements we continue to support. It is also where this documentation is generated. Many things are considered <em>experimental</em> and may change or break from time to time. While it may be difficult to be keep all things consistent when introducing new features, we continue to try our best to ensure backward compatibility.</p><section id="release-3-11-0_download"><h2><a href="#release-3-11-0_download">Download</a></h2><p>To download the newest version of Taskflow, please clone the master branch from <a href="https://github.com/taskflow/taskflow">Taskflow&#x27;s GitHub</a>.</p></section><section id="release-3-11-0_system_requirements"><h2><a href="#release-3-11-0_system_requirements">System Requirements</a></h2><p>To use Taskflow v3.11.0, you need a compiler that supports C++17:</p><ul><li>GNU C++ Compiler at least v8.4 with -std=c++17</li><li>Clang C++ Compiler at least v6.0 with -std=c++17</li><li>Microsoft Visual Studio at least v19.27 with /std:c++17</li><li>Apple Clang Xcode Version at least v12.0 with -std=c++17</li><li>Nvidia CUDA Toolkit and Compiler (nvcc) at least v11.1 with -std=c++17</li><li>Intel C++ Compiler at least v19.0.1 with -std=c++17</li><li>Intel DPC++ Clang Compiler at least v13.0.0 with -std=c++17</li></ul><p>Taskflow works on Linux, Windows, and Mac OS X.</p><aside class="m-note m-warning"><h4>Attention</h4><p>Although Taskflow supports primarily C++17, you can enable C++20 compilation through <code>-std=c++20</code> to achieve better performance due to new C++20 features.</p></aside></section><section id="release-3-11-0_summary"><h2><a href="#release-3-11-0_summary">Release Summary</a></h2></section><section id="release-3-11-0_new_features"><h2><a href="#release-3-11-0_new_features">New Features</a></h2><section id="release-3-11-0_taskflow_core"><h3><a href="#release-3-11-0_taskflow_core">Taskflow Core</a></h3><ul><li>added five benchmarks to showcase the capability of <a href="classtf_1_1Runtime.html" class="m-doc">tf::<wbr />Runtime</a><ul><li>fibonacci</li><li>skynet</li><li>integrate</li><li>nqueens</li><li>primes</li></ul></li></ul></section><section id="release-3-11-0_utilities"><h3><a href="#release-3-11-0_utilities">Utilities</a></h3></section></section><section id="release-3-11-0_bug_fixes"><h2><a href="#release-3-11-0_bug_fixes">Bug Fixes</a></h2></section><section id="release-3-11-0_breaking_changes"><h2><a href="#release-3-11-0_breaking_changes">Breaking Changes</a></h2></section><section id="release-3-11-0_documentation"><h2><a href="#release-3-11-0_documentation">Documentation</a></h2><ul><li>revised <a href="ExceptionHandling.html" class="m-doc">Exception Handling</a></li></ul></section><section id="release-3-11-0_miscellaneous_items"><h2><a href="#release-3-11-0_miscellaneous_items">Miscellaneous Items</a></h2><p>If you are interested in collaborating with us on applying Taskflow to your projects, please feel free to reach out to <a href="https://tsung-wei-huang.github.io/">Dr. Tsung-Wei Huang</a>!</p></section>
7272
</div>
7373
</div>
7474
</div>

docs/xml/ExceptionHandling.xml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
<tocsect>
2020
<name>Catch an Exception from a Corun Loop</name>
2121
<reference>ExceptionHandling_1CatchAnExceptionFromACorunLoop</reference>
22+
</tocsect>
23+
<tocsect>
24+
<name>Turn Off Exception Handling</name>
25+
<reference>ExceptionHandling_1TurnOffExceptionHandling</reference>
2226
</tocsect>
2327
</tableofcontents>
2428
<briefdescription>
@@ -240,7 +244,17 @@ An exception will automatically cancel the execution of its parent taskflow. All
240244
<codeline><highlight class="normal"><sp/><sp/><ref refid="cpp/io/basic_ostream" kindref="compound" external="/home/thuang295/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml">std::cout</ref><sp/>&lt;&lt;<sp/>re.what()<sp/>&lt;&lt;<sp/><ref refid="cpp/io/manip/endl" kindref="compound" external="/home/thuang295/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml">std::endl</ref>;</highlight></codeline>
241245
<codeline><highlight class="normal">}</highlight></codeline>
242246
</programlisting></para>
243-
<para>For the above example, if the exception is not caught with <ref refid="classtf_1_1Runtime_1a1c772e90614302024cfa52fa86d75cac" kindref="member">tf::Runtime::corun</ref>, it will be propagated to its parent task, which is the <ref refid="classtf_1_1Runtime" kindref="compound">tf::Runtime</ref> object <computeroutput>rt</computeroutput> in this case. Then, the exception will be propagated to <computeroutput>taskflow2</computeroutput>. </para>
247+
<para>For the above example, if the exception is not caught with <ref refid="classtf_1_1Runtime_1a1c772e90614302024cfa52fa86d75cac" kindref="member">tf::Runtime::corun</ref>, it will be propagated to its parent task, which is the <ref refid="classtf_1_1Runtime" kindref="compound">tf::Runtime</ref> object <computeroutput>rt</computeroutput> in this case. Then, the exception will be propagated to <computeroutput>taskflow2</computeroutput>.</para>
248+
</sect1>
249+
<sect1 id="ExceptionHandling_1TurnOffExceptionHandling">
250+
<title>Turn Off Exception Handling</title>
251+
<para>In some applications, exception handling may not be desirable due to performance concerns, coding style preferences, or platform constraints. Taskflow allows you to disable exception handling entirely at compile time. To do this, simply define the macro <computeroutput>TF_DISABLE_EXCEPTION_HANDLING</computeroutput> when compiling your program:</para>
252+
<para><programlisting filename=".cpp"><codeline><highlight class="normal">~$<sp/>g++<sp/>-DTF_DISABLE_EXCEPTION_HANDLING<sp/>your_taskflow_prog.cpp</highlight></codeline>
253+
</programlisting></para>
254+
<para>Disabling exception handling removes all try-catch blocks from the Taskflow runtime, resulting in a leaner binary and potentially faster execution. However, please note that this also means Taskflow will not catch or report runtime exceptions.</para>
255+
<para><simplesect kind="attention"><para>Disabling exception handling means that Taskflow will not catch or report runtime exceptions. Any exception thrown during execution will propagate unchecked and may cause your program to behave abnormally. Use this option only if you are confident that your application does not rely on exception safety. </para>
256+
</simplesect>
257+
</para>
244258
</sect1>
245259
</detaileddescription>
246260
<location file="doxygen/cookbook/exception.dox"/>

docs/xml/contributors.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
</listitem>
7272
<listitem><para><ulink url="https://github.com/xq114">Hoildkv</ulink>: fixed documentation errors in explaining the observer interface of executor </para>
7373
</listitem>
74+
<listitem><para><ulink url="https://github.com/IkeOTL">Isaac Yousuf</ulink>: fixed the bug in exception handling for worker loop </para>
75+
</listitem>
7476
<listitem><para><ulink url="https://ossia.io/">Jean Michael</ulink>: integrated Taskflow to the OSSIA project and reported feedback in comparison to TBB </para>
7577
</listitem>
7678
<listitem><para><ulink url="https://jw-liu.xyz/">Jiawei Liu</ulink>: fixed typos in the documentation </para>

docs/xml/release-3-11-0.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ Taskflow works on Linux, Windows, and Mac OS X.</para>
110110
</sect1>
111111
<sect1 id="release-3-11-0_1release-3-11-0_documentation">
112112
<title>Documentation</title>
113+
<para><itemizedlist>
114+
<listitem><para>revised <ref refid="ExceptionHandling" kindref="compound">Exception Handling</ref></para>
115+
</listitem></itemizedlist>
116+
</para>
113117
</sect1>
114118
<sect1 id="release-3-11-0_1release-3-11-0_miscellaneous_items">
115119
<title>Miscellaneous Items</title>

doxygen/contributing/contributors.dox

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ We are grateful for the following contributors (alphabetic order) to the %Taskfl
3232
@li <a href="https://github.com/guannan-git">Guannan Guo</a>: benchmarked different scheduling algorithms and architectures
3333
@li <a href="https://github.com/hjxy2012">Hjxy2012</a>: fixed the compilation error in nvcc due to removed features in C++17
3434
@li <a href="https://github.com/xq114">Hoildkv</a>: fixed documentation errors in explaining the observer interface of executor
35+
@li <a href="https://github.com/IkeOTL">Isaac Yousuf</a>: fixed the bug in exception handling for worker loop
3536
@li <a href="https://ossia.io/">Jean Michael</a>: integrated %Taskflow to the OSSIA project and reported feedback in comparison to TBB
3637
@li <a href="https://jw-liu.xyz/">Jiawei Liu</a>: fixed typos in the documentation
3738
@li <a href="https://github.com/juliangilbey">Junlian Gilbey</a>: added the explicit link to libatomic on some archs

doxygen/cookbook/exception.dox

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,23 @@ For the above example, if the exception is not caught with tf::Runtime::corun,
296296
it will be propagated to its parent task, which is the tf::Runtime object `rt` in this case.
297297
Then, the exception will be propagated to `taskflow2`.
298298

299+
@section TurnOffExceptionHandling Turn Off Exception Handling
300+
301+
In some applications, exception handling may not be desirable due to performance concerns, coding style preferences, or platform constraints. %Taskflow allows you to disable exception handling entirely at compile time.
302+
To do this, simply define the macro `TF_DISABLE_EXCEPTION_HANDLING` when compiling your program:
303+
304+
@code{.cpp}
305+
~$ g++ -DTF_DISABLE_EXCEPTION_HANDLING your_taskflow_prog.cpp
306+
@endcode
307+
308+
Disabling exception handling removes all try-catch blocks from the %Taskflow runtime, resulting in a leaner binary and potentially faster execution.
309+
However, please note that this also means %Taskflow will not catch or report runtime exceptions.
310+
311+
@attention
312+
Disabling exception handling means that %Taskflow will not catch or report runtime exceptions.
313+
Any exception thrown during execution will propagate unchecked and may cause your program to behave abnormally.
314+
Use this option only if you are confident that your application does not rely on exception safety.
315+
299316
*/
300317

301318
}

doxygen/releases/release-3.11.0.dox

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ through `-std=c++20` to achieve better performance due to new C++20 features.
5555

5656
@section release-3-11-0_documentation Documentation
5757

58+
+ revised @ref ExceptionHandling
59+
5860
@section release-3-11-0_miscellaneous_items Miscellaneous Items
5961

6062
If you are interested in collaborating with us on applying %Taskflow to your projects, please feel free to reach out to @twhuang!

taskflow/core/error.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,18 @@ void throw_re(const char* fname, const size_t line, ArgsT&&... args) {
7171

7272
#define TF_THROW(...) tf::throw_re(__FILE__, __LINE__, __VA_ARGS__);
7373

74+
// ----------------------------------------------------------------------------
75+
76+
#ifdef TF_DISABLE_EXCEPTION_HANDLING
77+
#define TF_EXECUTOR_EXCEPTION_HANDLER(worker, node, code_block) \
78+
code_block;
79+
#else
80+
#define TF_EXECUTOR_EXCEPTION_HANDLER(worker, node, code_block) \
81+
try { \
82+
code_block; \
83+
} catch(...) { \
84+
_process_exception(worker, node); \
85+
}
86+
#endif
87+
88+

taskflow/utility/macros.hpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,7 @@
4141
#define TF_UNLIKELY(x) (x)
4242
#endif
4343

44-
// ----------------------------------------------------------------------------
4544

46-
#ifdef TF_DISABLE_EXCEPTION_HANDLING
47-
#define TF_EXECUTOR_EXCEPTION_HANDLER(worker, node, code_block) \
48-
code_block;
49-
#else
50-
#define TF_EXECUTOR_EXCEPTION_HANDLER(worker, node, code_block) \
51-
try { \
52-
code_block; \
53-
} catch(...) { \
54-
_process_exception(worker, node); \
55-
}
56-
#endif
5745

5846
// ----------------------------------------------------------------------------
5947

0 commit comments

Comments
 (0)