Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Averaging slight adjustement for ensured thread safety #810

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nbollis
Copy link
Member

@nbollis nbollis commented Nov 26, 2024

In theory, the previous code was thread safe. However, additional steps were taken to ensure thread safety.

  • Import System.Collections.Concurrent for concurrent collections.
  • Change averagedPeaks from List to ConcurrentBag for thread safety.
  • Move binIncidences array creation outside parallel loop to avoid redundancy.
  • Modify Parallel.ForEach loop to use array length instead of list count.
  • Remove lock around averagedPeaks.Add as ConcurrentBag is thread-safe.

- Import `System.Collections.Concurrent` for concurrent collections.
- Change `averagedPeaks` from `List` to `ConcurrentBag` for thread safety.
- Move `binIncidences` array creation outside parallel loop to avoid redundancy.
- Modify `Parallel.ForEach` loop to use array length instead of list count.
- Remove `lock` around `averagedPeaks.Add` as `ConcurrentBag` is thread-safe.
@nbollis nbollis added the Maintenance The user isn't impacted by it, it's purely behind the scenes label Nov 26, 2024
Copy link

codecov bot commented Nov 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.21%. Comparing base (6411360) to head (094da3d).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #810      +/-   ##
==========================================
- Coverage   77.21%   77.21%   -0.01%     
==========================================
  Files         218      218              
  Lines       32966    32961       -5     
  Branches     3413     3412       -1     
==========================================
- Hits        25455    25450       -5     
  Misses       6944     6944              
  Partials      567      567              
Files with missing lines Coverage Δ
...b/SpectralAveraging/Algorithms/SpectraAveraging.cs 98.52% <100.00%> (-0.11%) ⬇️

@nbollis nbollis marked this pull request as ready for review November 26, 2024 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Maintenance The user isn't impacted by it, it's purely behind the scenes ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants