Skip to content

Comments

[work-in-progress][API] RuntimeFeature.IsMultithreadingSupported#124603

Draft
pavelsavara wants to merge 10 commits intodotnet:mainfrom
pavelsavara:IsMultithreadingSupported
Draft

[work-in-progress][API] RuntimeFeature.IsMultithreadingSupported#124603
pavelsavara wants to merge 10 commits intodotnet:mainfrom
pavelsavara:IsMultithreadingSupported

Conversation

@pavelsavara
Copy link
Member

@pavelsavara pavelsavara commented Feb 19, 2026

Fixes #77541
Continuation of #123329

@pavelsavara pavelsavara added this to the 11.0.0 milestone Feb 19, 2026
@pavelsavara pavelsavara self-assigned this Feb 19, 2026
Copilot AI review requested due to automatic review settings February 19, 2026 16:30
@pavelsavara pavelsavara added area-System.Threading os-browser Browser variant of arch-wasm labels Feb 19, 2026
Copy link
Contributor

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 pull request introduces a new public API RuntimeFeature.IsMultithreadingSupported to replace the internal Thread.IsSingleThreaded property. This is part of API proposal #77541 to provide a public feature flag for determining if multithreading is supported on the current platform (particularly relevant for single-threaded WebAssembly environments).

Changes:

  • Introduces public RuntimeFeature.IsMultithreadingSupported property and internal ThrowIfMultithreadingIsNotSupported() method
  • Removes internal Thread.IsSingleThreaded and Thread.ThrowIfSingleThreaded()
  • Renames PlatformDetection.IsThreadingSupportedIsMultithreadingSupported and IsNotWasmThreadingSupportedIsNotMultithreadingSupported
  • Updates hundreds of test files to use the new naming convention
  • Configures the feature switch in MSBuild targets for WebAssembly

Reviewed changes

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

Show a summary per file
File Description
System.Runtime.cs Adds public API surface for IsMultithreadingSupported
RuntimeFeature.cs Implements new property and internal throw helper
Thread.cs Removes old IsSingleThreaded API
PlatformDetection.cs (multiple) Updates to use RuntimeFeature instead of environment variable
Environment.cs Uses new API for ProcessorCount logic
Microsoft.NET.Sdk.WebAssembly.Browser.targets Configures feature switch for WASM
tests.browser.targets Removes IsBrowserThreadingSupported environment variable
200+ test files Updates ConditionalFact/Theory attributes to use new naming

Copilot AI review requested due to automatic review settings February 19, 2026 17:56
Copy link
Contributor

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 273 out of 273 changed files in this pull request and generated no new comments.

@jkotas
Copy link
Member

jkotas commented Feb 19, 2026

IsThreadingSupported -> IsMultithreadingSupported

Can you do 1 boring prep PR that has just this rename and nothing else, and do the rest in this PR? It is hard to find any interesting changes in 250+ changed files.

Copilot AI review requested due to automatic review settings February 20, 2026 08:01
Copy link
Contributor

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 273 out of 273 changed files in this pull request and generated no new comments.

@pavelsavara
Copy link
Member Author

pavelsavara commented Feb 20, 2026

Can you do 1 boring prep PR that has just this rename and nothing else, and do the rest in this PR? It is hard to find any interesting changes in 250+ changed files.

For now this is a draft on which I'm trying to make it compile. There is change of namespace and the new field doesn't exist in Net10/11.0.0-preview.1.26104.118 or lower (for which we build some tests).

Once I have passing build, I would try to make it easier to review. Perhaps this could be rebased as 3 commits ?

Copilot AI review requested due to automatic review settings February 20, 2026 12:18
@pavelsavara pavelsavara force-pushed the IsMultithreadingSupported branch from 26ff2f4 to 7b0c965 Compare February 20, 2026 12:18
Copy link
Contributor

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 292 out of 293 changed files in this pull request and generated 3 comments.

Copilot AI review requested due to automatic review settings February 20, 2026 12:34
Copy link
Contributor

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 292 out of 293 changed files in this pull request and generated 5 comments.

Copilot AI review requested due to automatic review settings February 20, 2026 16:04
Copy link
Contributor

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 292 out of 293 changed files in this pull request and generated 3 comments.

@pavelsavara pavelsavara force-pushed the IsMultithreadingSupported branch from 8904240 to 9b8972d Compare February 23, 2026 11:06
Copilot AI review requested due to automatic review settings February 23, 2026 11:33
Copy link
Contributor

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 34 out of 34 changed files in this pull request and generated 2 comments.

Copilot AI review requested due to automatic review settings February 23, 2026 13:10
Copy link
Contributor

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 34 out of 34 changed files in this pull request and generated 2 comments.

Comment on lines 75 to 92
/// <summary>
/// Gets a value that indicates whether the runtime supports multithreading, including
/// creating threads and using blocking synchronization primitives. This property
/// returns <see langword="false"/> on platforms that do not support multithreading,
/// such as browser and WASI.
/// </summary>
[UnsupportedOSPlatformGuard("browser")]
[UnsupportedOSPlatformGuard("wasi")]
[FeatureSwitchDefinition("System.Runtime.CompilerServices.RuntimeFeature.IsMultithreadingSupported")]
public static bool IsMultithreadingSupported { get; }
= AppContext.TryGetSwitch("System.Runtime.CompilerServices.RuntimeFeature.IsMultithreadingSupported", out bool isMultithreadingSupported) ? isMultithreadingSupported : true;

internal static void ThrowIfMultithreadingIsNotSupported()
{
if (!IsMultithreadingSupported)
{
throw new PlatformNotSupportedException();
}
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

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

IsMultithreadingSupported defaults to true when the AppContext switch isn't set, but the XML doc and platform guards state it returns false on unsupported platforms like browser/WASI. I couldn't find any non-browser wiring for this switch (only Browser.targets sets it), so on WASI (and any single-threaded host missing the config) this will incorrectly report true and may allow thread/blocking paths to run. Consider defaulting based on platform/feature defines (e.g., #if FEATURE_SINGLE_THREADED => false, otherwise check OperatingSystem.IsBrowser()/IsWasi() or ensure the host sets the switch for WASI as well).

Copilot uses AI. Check for mistakes.
Comment on lines +133 to 134
[SkipOnPlatform(TestPlatforms.Browser, "Requires threads")]
[Fact]
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

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

This test creates/joins threads; if WASI is also single-threaded (as implied by the new RuntimeFeature guards elsewhere), it should be skipped there as well. Consider skipping on TestPlatforms.Wasi (or using a multithreading-supported condition) to avoid runtime failures on WASI test runs.

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings February 23, 2026 14:13
Copy link
Contributor

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 34 out of 34 changed files in this pull request and generated no new comments.

public static bool IsMultithreadingSupported => (!IsWasi && !IsBrowser) || IsWasmThreadingSupported;

// TODO-WASM: https://github.com/dotnet/runtime/issues/124748
// this is compiled with 11.0.0-preview.1.26104.118\ref
Copy link
Member

Choose a reason for hiding this comment

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

Why is this compiled against stale references?

I would expect that the libraries tests are always built against the live references. Otherwise, we would not be able to add new public APIs and their tests in the same PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know

Copy link
Member

Choose a reason for hiding this comment

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

This file compiles for both live .NET and .NET Standard. Maybe that's the problem?

Other places in this file deal with it by #if NET and implementing fallback for .NET Standard under #if !NET.

Copy link
Member Author

Choose a reason for hiding this comment

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

I saw nuget path in the binlog, I think it was not .NET Standard problem. I can try again ...

…Wait.cs

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Copilot AI review requested due to automatic review settings February 23, 2026 16:24
Copy link
Contributor

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 34 out of 34 changed files in this pull request and generated no new comments.

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

Labels

area-System.Threading os-browser Browser variant of arch-wasm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API Proposal]: RuntimeFeature.IsMultithreadingSupported

3 participants