fix(utils/parallel): prevent deadlock on single-core systems and with empty arrays #9597
+54
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This pull request:
fixes a deadlock bug in
@stdlib/utils/parallelwhere the function would hang indefinitely on single-core systems (numCPUs = 1) because defaults would setworkers = 0. a deadlock bug when called with empty arrays (parallel([])) where clamping logic would reduce workers to 0.fixes a deadlock bug when explicitly passing
{workers: 0, concurrency: 0}options and updateddefaults.jsto use@stdlib/math/base/special/fast/maxto ensure minimum of 1 worker/concurrency as suggested by maintainer ,adds safeguard inmain.jsto prevent workers/concurrency from dropping below 1 after clamping logic , tests covering all three edge cases.Related Issues
This pull request has the following related issues:
Questions
No.
Other
This fix was discussed with maintainer @kgryte who suggested using
@stdlib/math/base/special/fast/maxfor the defaults.js fix. The safeguard in main.js was added to handle edge cases where clamping could still result in 0 workers even with the defaults fix.Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
N/A
@stdlib-js/reviewers
[contributing]: https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md