Feature and ifdef FEATURE_MULTITHREADING#124959
Feature and ifdef FEATURE_MULTITHREADING#124959pavelsavara wants to merge 21 commits intodotnet:mainfrom
Conversation
There was a problem hiding this comment.
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
FeatureWasmManagedThreadstoFeatureIsMultithreadingSupportedacross all project files - Renamed C# preprocessor define
FEATURE_WASM_MANAGED_THREADStoFEATURE_IS_MULTITHREADING_SUPPORTED - Removed
FEATURE_SINGLE_THREADEDandFeatureSingleThreadin favor of checking!FEATURE_IS_MULTITHREADING_SUPPORTED - Updated documentation in
threads.mdto reflect the new naming - Updated C/C++ PAL layer code to use
FEATURE_IS_MULTITHREADING_SUPPORTED(with appropriate#ifdef/#ifndefusage)
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 |
src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs
Outdated
Show resolved
Hide resolved
|
We do not have any I think it should be |
4ecec3d to
91b8eb2
Compare
src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Threading/Monitor.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Threading/src/System/Threading/CountdownEvent.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Threading.Tasks.Parallel/src/System.Threading.Tasks.Parallel.csproj
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/ref/System.Private.CoreLib.ExtraApis.cs
Outdated
Show resolved
Hide resolved
...System.Net.WebSockets.Client/src/System/Net/WebSockets/BrowserWebSockets/BrowserWebSocket.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Threading.ThreadPool/ref/System.Threading.ThreadPool.cs
Show resolved
Hide resolved
58c66fa to
97013a8
Compare
...System.Net.WebSockets.Client/src/System/Net/WebSockets/BrowserWebSockets/BrowserWebSocket.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
…b.csproj Co-authored-by: Jan Kotas <jkotas@microsoft.com>
| <DefineConstants Condition="'$(FeatureWasmManagedThreads)' == 'true'" >$(DefineConstants);FEATURE_WASM_MANAGED_THREADS</DefineConstants> | ||
| <EmitCompilerGeneratedFiles Condition="'$(Configuration)' == 'Debug' and '$(TargetPlatformIdentifier)' == 'browser'">true</EmitCompilerGeneratedFiles> | ||
| </PropertyGroup> | ||
|
|
There was a problem hiding this comment.
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.
| <PropertyGroup Condition="'$(TargetPlatformIdentifier)' == 'browser' and '$(WasmEnableThreads)' == 'true'"> | |
| <DefineConstants>$(DefineConstants);FEATURE_WASM_MANAGED_THREADS</DefineConstants> | |
| </PropertyGroup> |
src/libraries/System.Net.WebSockets.Client/src/System.Net.WebSockets.Client.csproj
Show resolved
Hide resolved
…ockets.Client.csproj
src/libraries/System.Net.WebSockets.Client/src/System.Net.WebSockets.Client.csproj
Outdated
Show resolved
Hide resolved
…ockets.Client.csproj
src/libraries/System.Net.WebSockets.Client/src/System.Net.WebSockets.Client.csproj
Outdated
Show resolved
Hide resolved
…ockets.Client.csproj
| <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')" /> |
There was a problem hiding this comment.
| <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'"> |
There was a problem hiding this comment.
| <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'" /> |
There was a problem hiding this comment.
| <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" /> |
There was a problem hiding this comment.
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.
No description provided.