Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>No, it is not OK to leave a critical section with exceptions. <code>g++</code> does not complain in this case but it silently inserts an implicit <code>try/catch</code> around the block of the critical section. For example the following code:</p> <pre><code>#pragma omp critical (my_crit) { throw 3; } </code></pre> <p>gets lowered by the OpenMP processor of GCC 4.7 into:</p> <pre><code>#pragma omp critical (my_crit) __builtin_GOMP_critical_name_start (&amp;.gomp_critical_user_my_crit); try { D.20639 = __cxa_allocate_exception (4); try { MEM[(int *)D.20639] = 3; } catch { __cxa_free_exception (D.20639); } __cxa_throw (D.20639, &amp;_ZTIi, 0B); } catch { &lt;&lt;&lt;eh_must_not_throw (terminate)&gt;&gt;&gt; } __builtin_GOMP_critical_name_end (&amp;.gomp_critical_user_my_crit); </code></pre> <p>Reaching the implicit built-in catch-all handler <code>&lt;&lt;&lt;eh_must_not_throw (terminate)&gt;&gt;&gt;</code> results in quite ungraceful termination:</p> <pre><code>terminate called after throwing an instance of 'int' Abort trap: 6 </code></pre> <p>The implicit <code>try/catch</code> is inserted regardless of the presence of an outer <code>try/catch</code> construct, i.e. the exception would never ever leave the <code>critical</code> section.</p> <p>The OpenMP standard mandates, that if an exception is thrown within most OpenMP constructs (<code>parallel</code>, <code>section</code>, <code>master</code>, <code>single</code>, <code>for</code>, <code>critical</code>, <code>task</code>, etc.), execution must resume within the same construct and that the same thread must catch the exception. Violation of this restriction leads to non-conformant OpenMP code and <code>g++</code> simply enforces the conformance by inserting <code>try/catch</code> blocks with termination handlers inside all such constructs.</p> <p>As for the error when a <code>return</code> statement is present, OpenMP defines a strcutured block in C/C++ as:</p> <blockquote> <p>For C/C++, an executable statement, possibly compound, with a single entry at the top and a single exit at the bottom, or an OpenMP construct.</p> </blockquote> <p>and also (for all languages):</p> <blockquote> <p>The point of exit cannot be a branch out of the <em>structured block</em>.</p> </blockquote> <p>Obviously <code>return</code> constitutes a branch ouf of the block, different from simply falling of the bottom of the block.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload