Skip to content

Feature and ifdef FEATURE_MULTITHREADING#124959

Open
pavelsavara wants to merge 21 commits intodotnet:mainfrom
pavelsavara:FEATURE_IS_MULTITHREADING_SUPPORTED
Open

Feature and ifdef FEATURE_MULTITHREADING#124959
pavelsavara wants to merge 21 commits intodotnet:mainfrom
pavelsavara:FEATURE_IS_MULTITHREADING_SUPPORTED

Conversation

@pavelsavara
Copy link
Member

No description provided.

@pavelsavara pavelsavara added this to the 11.0.0 milestone Feb 27, 2026
@pavelsavara pavelsavara self-assigned this Feb 27, 2026
Copilot AI review requested due to automatic review settings February 27, 2026 11:40
@pavelsavara pavelsavara added arch-wasm WebAssembly architecture os-browser Browser variant of arch-wasm labels Feb 27, 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 PR refactors the threading feature detection mechanism in the .NET runtime by consolidating multiple threading-related feature flags into a single, consistently-named flag: FEATURE_IS_MULTITHREADING_SUPPORTED. This replaces the previous FEATURE_WASM_MANAGED_THREADS and FEATURE_SINGLE_THREADED flags with clearer, more consistent naming.

Changes:

  • Renamed MSBuild property FeatureWasmManagedThreads to FeatureIsMultithreadingSupported across all project files
  • Renamed C# preprocessor define FEATURE_WASM_MANAGED_THREADS to FEATURE_IS_MULTITHREADING_SUPPORTED
  • Removed FEATURE_SINGLE_THREADED and FeatureSingleThread in favor of checking !FEATURE_IS_MULTITHREADING_SUPPORTED
  • Updated documentation in threads.md to reflect the new naming
  • Updated C/C++ PAL layer code to use FEATURE_IS_MULTITHREADING_SUPPORTED (with appropriate #ifdef/#ifndef usage)

Reviewed changes

Copilot reviewed 68 out of 68 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/mono/wasm/threads.md Updated documentation to reference new feature flag name
src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj Consolidated feature properties, removed separate single-thread property
src/mono/System.Private.CoreLib/src/System/Threading/Monitor.Mono.cs Updated preprocessor directive
src/libraries/System.Threading/src/System.Threading.csproj Updated feature property definition and condition logic
src/libraries/System.Threading/src/System/Threading/*.cs Updated preprocessor directives in source files
src/libraries/System.Threading/ref/System.Threading.cs Updated preprocessor directives in reference assembly
src/libraries/System.Threading.Thread*/ref/*.csproj Updated feature property references in WebAssembly threading projects
src/libraries/System.Threading.ThreadPool*/ref/*.csproj Updated feature property references
src/libraries/System.Threading.Tasks.Parallel/src/*.csproj Removed separate single-thread flag, using unified flag
src/libraries/System.Runtime.InteropServices.JavaScript/src/*.cs Updated all preprocessor directives across JavaScript interop
src/libraries/System.Runtime.InteropServices.JavaScript/src/*.csproj Updated feature property and conditions
src/libraries/System.Runtime.InteropServices.JavaScript/tests/*.cs Updated test code preprocessor directives
src/libraries/System.Private.CoreLib/src/System/Threading/*.cs Updated threading implementation files
src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeFeature.cs Refactored conditional compilation blocks
src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems Updated file inclusion conditions
src/libraries/System.Private.CoreLib/ref/*.cs Updated reference assembly definitions
src/libraries/System.Net.WebSockets.Client/src/*.cs Updated WebSocket implementation
src/libraries/System.Net.Http/src/System.Net.Http.csproj Removed unused feature property
src/libraries/System.Linq.Parallel/src/*.cs Updated PLINQ implementation files
src/libraries/System.Linq.Parallel/src/System.Linq.Parallel.csproj Consolidated feature flags
src/libraries/Common/src/Interop/Browser/Interop.Runtime.Mono.cs Updated interop declarations
src/coreclr/pal/src/thread/*.cpp Updated PAL thread implementation with inverted conditional logic
src/coreclr/pal/src/synchmgr/*.cpp Updated synchronization manager implementation
src/coreclr/pal/src/CMakeLists.txt Updated CMake definitions
src/coreclr/clrdefinitions.cmake Updated CMake feature definitions
src/coreclr/clr.featuredefines.props Consolidated feature properties
eng/native.wasm.targets Updated native build conditions and CMake arguments

@jkotas
Copy link
Member

jkotas commented Feb 27, 2026

We do not have any FEATURE_IS_.*. FEATURE_ABC means ABC is supported.

I think it should be FeatureMultithreadingSupport / FEATURE_MULTITHREADING_SUPPORT, or just FeatureMultithreading / FEATURE_MULTITHREADING, to match the naming pattern we use for the feature properties and defines.

Copilot AI review requested due to automatic review settings February 27, 2026 14:47
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 68 out of 68 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings February 27, 2026 16:48
@pavelsavara pavelsavara force-pushed the FEATURE_IS_MULTITHREADING_SUPPORTED branch from 4ecec3d to 91b8eb2 Compare February 27, 2026 16:48
@pavelsavara pavelsavara changed the title Feature and ifdef FEATURE_IS_MULTITHREADING_SUPPORTED Feature and ifdef FEATURE_MULTITHREADING Feb 27, 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

Copilot reviewed 74 out of 74 changed files in this pull request and generated 5 comments.

Copilot AI review requested due to automatic review settings February 27, 2026 17:25
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 74 out of 74 changed files in this pull request and generated 5 comments.

@pavelsavara pavelsavara force-pushed the FEATURE_IS_MULTITHREADING_SUPPORTED branch from 58c66fa to 97013a8 Compare February 27, 2026 18:34
Copilot AI review requested due to automatic review settings March 4, 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 25 out of 25 changed files in this pull request and generated no new comments.

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Copilot AI review requested due to automatic review settings March 5, 2026 02:09
…b.csproj

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
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 25 out of 25 changed files in this pull request and generated 2 comments.

<DefineConstants Condition="'$(FeatureWasmManagedThreads)' == 'true'" >$(DefineConstants);FEATURE_WASM_MANAGED_THREADS</DefineConstants>
<EmitCompilerGeneratedFiles Condition="'$(Configuration)' == 'Debug' and '$(TargetPlatformIdentifier)' == 'browser'">true</EmitCompilerGeneratedFiles>
</PropertyGroup>

Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

System.Net.WebSockets.Client no longer defines FEATURE_WASM_MANAGED_THREADS, but BrowserWebSocket.Dispose() still uses #if FEATURE_WASM_MANAGED_THREADS to decide whether to marshal cleanup onto the JS synchronization context. With the define removed, threaded WASM builds will always take the non-threaded path, which can break cleanup when Dispose runs on the finalizer thread. Re-introduce the define for the browser target when WasmEnableThreads=true, or update the source to key off the new multithreading define/property consistently.

Suggested change
<PropertyGroup Condition="'$(TargetPlatformIdentifier)' == 'browser' and '$(WasmEnableThreads)' == 'true'">
<DefineConstants>$(DefineConstants);FEATURE_WASM_MANAGED_THREADS</DefineConstants>
</PropertyGroup>

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings March 5, 2026 04:58
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 25 out of 25 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings March 5, 2026 05:06
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 25 out of 25 changed files in this pull request and generated no new comments.

Comment on lines +1602 to +1603
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\EventPipeEventDispatcher.Threads.cs" Condition="'$(FeaturePerfTracing)' == 'true' and (('$(TargetsWasi)' != 'true' and '$(TargetsBrowser)' != 'true') or '$(FeatureMultithreading)' == 'true')" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\EventPipeEventDispatcher.Wasm.cs" Condition="'$(FeaturePerfTracing)' == 'true' and (('$(TargetsWasi)' == 'true' or '$(TargetsBrowser)' == 'true') and '$(FeatureMultithreading)' != 'true')" />
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\EventPipeEventDispatcher.Threads.cs" Condition="'$(FeaturePerfTracing)' == 'true' and (('$(TargetsWasi)' != 'true' and '$(TargetsBrowser)' != 'true') or '$(FeatureMultithreading)' == 'true')" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\EventPipeEventDispatcher.Wasm.cs" Condition="'$(FeaturePerfTracing)' == 'true' and (('$(TargetsWasi)' == 'true' or '$(TargetsBrowser)' == 'true') and '$(FeatureMultithreading)' != 'true')" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\EventPipeEventDispatcher.Threads.cs" Condition="'$(FeaturePerfTracing)' == 'true' and '$(FeatureMultithreading)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\EventPipeEventDispatcher.Wasm.cs" Condition="'$(FeaturePerfTracing)' == 'true' and '$(FeatureMultithreading)' != 'true')" />

<Compile Include="$(MSBuildThisFileDirectory)System\Threading\Backoff.cs" />
</ItemGroup>
<ItemGroup Condition="('$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true') and '$(FeatureWasmManagedThreads)' != 'true'">
<ItemGroup Condition="('$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true') and '$(FeatureMultithreading)' != 'true'">
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<ItemGroup Condition="('$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true') and '$(FeatureMultithreading)' != 'true'">
<ItemGroup Condition="'$(FeatureMultithreading)' != 'true'">

<Compile Include="$(MSBuildThisFileDirectory)System\Threading\PreAllocatedOverlapped.Unix.cs" Condition="'$(TargetsUnix)' == 'true' or ('$(TargetsBrowser)' == 'true' and '$(FeatureWasmManagedThreads)' == 'true')" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\PreAllocatedOverlapped.Portable.cs" Condition="('$(TargetsBrowser)' != 'true' and '$(TargetsWasi)' != 'true') or '$(FeatureWasmManagedThreads)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\PreAllocatedOverlapped.Unix.cs" Condition="'$(TargetsUnix)' == 'true' or ('$(TargetsBrowser)' == 'true' and '$(FeatureMultithreading)' == 'true')" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\PreAllocatedOverlapped.Portable.cs" Condition="('$(TargetsBrowser)' != 'true' and '$(TargetsWasi)' != 'true') or '$(FeatureMultithreading)' == 'true'" />
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\PreAllocatedOverlapped.Portable.cs" Condition="('$(TargetsBrowser)' != 'true' and '$(TargetsWasi)' != 'true') or '$(FeatureMultithreading)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\PreAllocatedOverlapped.Portable.cs" Condition="'$(FeatureMultithreading)' == 'true'" />

</ItemGroup>
<ItemGroup Condition="('$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true') and '$(FeatureWasmManagedThreads)' != 'true'">
<ItemGroup Condition="('$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true') and '$(FeatureMultithreading)' != 'true'">
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\PreAllocatedOverlapped.Browser.cs" />
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason why we cannot use PreAllocatedOverlapped.Portable.cs for single-threaded Wasm? It should be unreachable trimmable code on non-Windows, so it should not affect size of retail apps.

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

Labels

arch-wasm WebAssembly architecture area-Infrastructure-libraries os-browser Browser variant of arch-wasm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants