Skip to content

Conversation

@shiavm006
Copy link
Contributor

Description

What is the purpose of this pull request?

This pull request:

fixes a deadlock bug in @stdlib/utils/parallel where the function would hang indefinitely on single-core systems (numCPUs = 1) because defaults would set workers = 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 updated defaults.js to use @stdlib/math/base/special/fast/max to ensure minimum of 1 worker/concurrency as suggested by maintainer ,adds safeguard in main.js to prevent workers/concurrency from dropping below 1 after clamping logic , tests covering all three edge cases.

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

  • No related issue (discussed with maintainer @kgryte via direct message)

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

This fix was discussed with maintainer @kgryte who suggested using @stdlib/math/base/special/fast/max for 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

Please ensure the following tasks are completed before submitting this pull request.

  • Read, understood, and followed the [contributing guidelines][contributing].

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".

N/A


@stdlib-js/reviewers
[contributing]: https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md

@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Jan 7, 2026
Empty arrays are rejected by validation before the safeguard runs, so this test case is invalid. The safeguard still protects against single-core systems and explicit zero values.
@shiavm006
Copy link
Contributor Author

cc @kgryte i verified it locally ya u can check it out like can disscuss on changes and implement that same

@stdlib-bot
Copy link
Contributor

stdlib-bot commented Jan 7, 2026

Coverage Report

Package Statements Branches Functions Lines
utils/parallel $\color{green}1363/1363$
$\color{green}+0.00%$
$\color{red}148/149$
$\color{green}+0.00%$
$\color{green}35/35$
$\color{green}+0.00%$
$\color{green}1363/1363$
$\color{green}+0.00%$

The above coverage report was generated for the changes in this PR.

@shiavm006
Copy link
Contributor Author

@kgryte what u think about it

Signed-off-by: Athan <[email protected]>
Copy link
Member

@kgryte kgryte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kgryte kgryte removed the Needs Review A pull request which needs code review. label Jan 10, 2026
@kgryte kgryte changed the title fix(utils/parallel): prevent deadlock on single-core systems and with empty arrays fix: prevent deadlock on single-core systems and with empty arrays in utils/parallel Jan 10, 2026
@kgryte kgryte merged commit 20e08f9 into stdlib-js:develop Jan 10, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants