Skip to content

[browser][mono][MT] Prep for emscripten upgrade#129503

Merged
pavelsavara merged 17 commits into
dotnet:mainfrom
pavelsavara:browser_mt
Jun 19, 2026
Merged

[browser][mono][MT] Prep for emscripten upgrade#129503
pavelsavara merged 17 commits into
dotnet:mainfrom
pavelsavara:browser_mt

Conversation

@pavelsavara

@pavelsavara pavelsavara commented Jun 17, 2026

Copy link
Copy Markdown
Member

This is in prep for emscripten bump which changes MT significantly. JS interop is broken in MT.

  • Fix MT sample and Common.Tests
  • set RuntimeFeature.IsMultithreadingSupported
  • worker.queue and early subscription to responses
  • replace mono_wasm_pthread_ptr with pthread_self

@pavelsavara pavelsavara added this to the 11.0.0 milestone Jun 17, 2026
@pavelsavara pavelsavara self-assigned this Jun 17, 2026
@pavelsavara pavelsavara added the arch-wasm WebAssembly architecture label Jun 17, 2026
Copilot AI review requested due to automatic review settings June 17, 2026 05:55
@pavelsavara pavelsavara added area-VM-threading-mono os-browser Browser variant of arch-wasm labels Jun 17, 2026
@pavelsavara

Copy link
Copy Markdown
Member Author

/azp run runtime-wasm

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 updates the Mono browser (WASM threads) runtime and sample to align with expected Emscripten threading/runtime changes: switching pthread id retrieval to pthread_self, passing a compiled WebAssembly.Module into workers, and ensuring PThread is exported at link time.

Changes:

  • Update pthread identity and worker startup plumbing (use pthread_self, propagate wasmModule/wasmMemory/handler metadata to workers, adjust when preRunWorker runs).
  • Adjust default pthread pool sizing and the browser-threads sample configuration/build properties.
  • Export Emscripten PThread as an exported runtime method when threads are enabled.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/mono/sample/wasm/browser-threads/wwwroot/main.js Sets a larger pthreadPoolInitialSize in the sample config.
src/mono/sample/wasm/browser-threads/Wasm.Browser.Threads.Sample.csproj Tweaks WASM build properties for debugging/asset behavior during the upgrade prep.
src/mono/browser/runtime/types/internal.ts Updates Emscripten module typing (wasmModule now a WebAssembly.Module + adds wasmMemory/handlers).
src/mono/browser/runtime/startup.ts Switches to pthread_self, adjusts worker instantiation flow, and calls preRunWorker after instantiation.
src/mono/browser/runtime/pthreads/worker-thread.ts Removes mono_wasm_pthread_ptr usage and adjusts worker lifecycle hooks.
src/mono/browser/runtime/pthreads/ui-thread.ts Changes worker message handling and loads wasm module before wiring message handling.
src/mono/browser/runtime/pthreads/shared.ts Removes mono_wasm_pthread_ptr helper.
src/mono/browser/runtime/pthreads/index.ts Stops re-exporting mono_wasm_pthread_ptr.
src/mono/browser/runtime/loader/worker.ts Worker-side config receive path updated to accept richer payload (module/memory/handlers).
src/mono/browser/runtime/loader/config.ts Changes default pthreadPoolInitialSize (5 → 7).
src/mono/browser/runtime/cwraps.ts Adds pthread_self cwrap signature.
src/mono/browser/build/BrowserWasmApp.targets Exports PThread via EXPORTED_RUNTIME_METHODS when threads enabled.

Comment thread src/mono/browser/runtime/loader/worker.ts Outdated
Comment thread src/mono/browser/runtime/pthreads/worker-thread.ts
Comment thread src/mono/browser/runtime/pthreads/worker-thread.ts
Comment thread src/mono/browser/runtime/pthreads/ui-thread.ts
@pavelsavara pavelsavara reopened this Jun 17, 2026
Copilot AI review requested due to automatic review settings June 17, 2026 15:57
@pavelsavara pavelsavara marked this pull request as ready for review June 17, 2026 16:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread src/mono/browser/runtime/pthreads/ui-thread.ts Outdated
Comment thread src/mono/browser/runtime/pthreads/ui-thread.ts Outdated
Comment thread src/mono/browser/runtime/loader/worker.ts Outdated
Comment thread src/libraries/tests.proj
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 17, 2026 16:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread src/mono/browser/runtime/pthreads/worker-thread.ts
Comment thread src/mono/browser/runtime/pthreads/worker-thread.ts
Copilot AI review requested due to automatic review settings June 18, 2026 09:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 24 out of 24 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System.Runtime.InteropServices.JavaScript.Tests.csproj:68

  • This change comments out the entire ItemGroup that includes the WebWorker-specific test sources for WasmEnableThreads == true. Leaving test sources disabled via an XML comment makes it easy to forget to re-enable them, and removes coverage for MT scenarios.

If these tests are temporarily broken, prefer an explicit MSBuild condition (or an ActiveIssue/ConditionalFact-based skip inside the tests) so the intent is discoverable and can be reverted cleanly. Otherwise, please re-enable the ItemGroup.

  <!--
  <ItemGroup Condition="'$(WasmEnableThreads)' == 'true'">
    <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\JavaScript\WebWorkerTestBase.cs" />
    <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\JavaScript\WebWorkerTest.cs" />
    <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\JavaScript\WebWorkerTest.Http.cs" />

Comment thread src/mono/browser/runtime/pthreads/ui-thread.ts Outdated
@pavelsavara

Copy link
Copy Markdown
Member Author

/azp run runtime-wasm

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Comment thread src/mono/sample/wasm/browser-advanced/Wasm.Advanced.Sample.csproj
@pavelsavara

Copy link
Copy Markdown
Member Author

/azp run runtime-wasm

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara

Copy link
Copy Markdown
Member Author

/ba-g known failures

@pavelsavara pavelsavara merged commit 5b69dce into dotnet:main Jun 19, 2026
90 of 108 checks passed
@pavelsavara pavelsavara deleted the browser_mt branch June 19, 2026 06:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-VM-threading-mono os-browser Browser variant of arch-wasm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants