computablee / DotMP

A collection of powerful abstractions for parallel programming in .NET with an OpenMP-like API.
https://computablee.github.io/DotMP/
GNU Lesser General Public License v2.1
29 stars 8 forks source link

Implement proper exception handling from threads #103

Closed computablee closed 11 months ago

computablee commented 11 months ago

Which issue are you addressing?

Not an open issue, but needed to be done.

The problem was that exceptions thrown from within a ParallelRegion could only be caught from within the ParallelRegion, and not outside of it. This is because a Thread would terminate with an exception, which could not be caught from the main thread. This was troublesome and counter-intuitive from a programmer's perspective.

How have you addressed the issue?

Creation of each thread now includes a try-catch block. If an exception is thrown from within a thread, that thread will set an exception object accessible to the main thread, then proceed to interrupt all other threads. Then, once all threads have joined, the main thread checks the exception object and, if set, will rethrow the exception, preserving the stack trace.

How have you tested your patch?

All of the *_should_except methods in DotMPTests have been rewritten to have the Assert.Throws in the outermost scope. This ensures that all exceptions can be caught from outside of ParallelRegions.

codecov[bot] commented 11 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (e38d93a) 99.10% compared to head (087c7bf) 99.12%. Report is 1 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #103 +/- ## ========================================== + Coverage 99.10% 99.12% +0.01% ========================================== Files 12 12 Lines 1120 1138 +18 Branches 110 113 +3 ========================================== + Hits 1110 1128 +18 Misses 5 5 Partials 5 5 ``` | [Files](https://app.codecov.io/gh/computablee/DotMP/pull/103?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Phillip+Allen+Lane) | Coverage Δ | | |---|---|---| | [DotMP/ForkedRegion.cs](https://app.codecov.io/gh/computablee/DotMP/pull/103?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Phillip+Allen+Lane#diff-RG90TVAvRm9ya2VkUmVnaW9uLmNz) | `100.00% <100.00%> (ø)` | | | [DotMP/Iter.cs](https://app.codecov.io/gh/computablee/DotMP/pull/103?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Phillip+Allen+Lane#diff-RG90TVAvSXRlci5jcw==) | `94.59% <ø> (ø)` | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.