Skip to content

Fix thread::available_parallelism on WASI targets with threads#153604

Open
surban wants to merge 1 commit intorust-lang:mainfrom
rust-wasi-web:wasi-available-parallelism-fix
Open

Fix thread::available_parallelism on WASI targets with threads#153604
surban wants to merge 1 commit intorust-lang:mainfrom
rust-wasi-web:wasi-available-parallelism-fix

Conversation

@surban
Copy link
Contributor

@surban surban commented Mar 9, 2026

The refactoring in ba46286 ("std: Use more unix.rs code on WASI targets") moved WASI from its own thread module into the shared unix.rs module. However, it did not carry over the available_parallelism() implementation for WASI with threads, causing it to fall through to the unsupported catch-all. This silently regressed the support originally added in f0b7008.

Fix this by adding a dedicated cfg_select arm for WASI with atomics.
Plain wasip1 without threads continues to return unsupported, matching the previous behavior.

Copilot AI review requested due to automatic review settings March 9, 2026 10:31
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 9, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 9, 2026

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ChrisDenton, libs
  • @ChrisDenton, libs expanded to 8 candidates

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR restores thread::available_parallelism() support for WASI targets compiled with the atomics target feature. A prior refactoring (ba462864f11) unified WASI into the shared unix.rs thread module but failed to migrate the WASI+atomics implementation of available_parallelism(), causing it to silently fall through to the unsupported catch-all.

Changes:

  • Adds a dedicated cfg_select arm for all(target_os = "wasi", target_feature = "atomics") in available_parallelism() that calls libc::sysconf with a hardcoded constant _SC_NPROCESSORS_ONLN = 84 (since the libc crate does not export this constant for WASI targets).
  • Plain wasip1 without threads continues to fall through to the _ arm and return an unsupported error, matching pre-regression behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

View changes since this review

The refactoring in ba46286 ("std: Use more unix.rs code on WASI
targets") moved WASI from its own thread module into the shared unix.rs
module. However, it did not carry over the available_parallelism()
implementation for WASI with threads, causing it to fall through to the
unsupported catch-all. This silently regressed the support originally
added in f0b7008.

Fix this by adding a dedicated cfg_select arm for WASI with atomics
that calls sysconf(_SC_NPROCESSORS_ONLN). The constant is defined
locally because the libc crate does not yet export it for WASI targets.
Plain wasip1 without threads continues to return unsupported, matching
the previous behavior.
@surban surban force-pushed the wasi-available-parallelism-fix branch from 6ca9426 to 0fcb2b0 Compare March 9, 2026 10:37
@surban surban requested a review from Copilot March 9, 2026 11:05
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants