runtime/wasm: support blocking primitives (based on #2197) - #2198
Draft
cpunion wants to merge 28 commits into
Draft
runtime/wasm: support blocking primitives (based on #2197)#2198cpunion wants to merge 28 commits into
cpunion wants to merge 28 commits into
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
27 tasks
cpunion
force-pushed
the
codex/wasm-blocking-primitives
branch
from
July 28, 2026 14:15
18c2966 to
c45e243
Compare
…/wasm-wasi-single-worker
…orker-asyncify-scheduler # Conflicts: # internal/build/source_patch_test.go
…/wasm-wasi-single-worker
…orker-asyncify-scheduler # Conflicts: # runtime/internal/runtime/z_default.go
…/wasm-wasi-single-worker
51 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Depends on #2197.
Tracks the B: blocking primitives stage of #2152.
Problem
The single-worker WebAssembly scheduler from #2197 can park and resume goroutines, but channels and the standard
syncpackage still wait through pthread mutexes and condition variables. On the default JS and WASI P1 single-worker runtimes, such a wait blocks the only execution owner, so another runnable goroutine cannot make progress and wake it. It also keeps pthread synchronization coupled to builds that otherwise need no wasm threads.Implementation
runtime/internal/runtime; channel/select code uses a small build-specific wait adapter without exposing scheduler-ownedgstate.sync/atomic.Value, and relatedinternal/syncandinternal/pollhooks.LLGO_WASI_THREADS=1P1 builds.internal/syncsource replacement on Go 1.24+ and avoid non-void defer lowering that crashes LLVM 22 while compiling the upstream hash-trie map implementation.The runtime boundary remains narrow: channel code knows only lock/signal adapters, synchronization code knows only the opaque park/ready handle, and target-specific scheduling stays in the scheduler backend.
Compatibility
Validation
Local tests were run with
GOMAXPROCS=2and-p=1.go test ./...; J64 and J32 execution; default P1 execution; explicit P1 threads build and wasm validation.test/go, runtime module, nativetest/std/sync, J32/J64/P1 execution, explicit P1 threads build,-O0,-O2,-O3, and ThinLTO.internal/build, runtime module, default P1 execution under Wasmtime 39, and explicit P1 threads build/parse validation in a container limited to 15 GiB and 2 CPUs. Peak observed memory remained about 1.2 GiB.cortex-m-qemuempty ELF is byte-identical (132,924-byte file, 4,188-byte text); native hello and sync fixtures add 928 and 920 bytes of loaded sections respectively (about 0.05%), while__textis 108 bytes smaller in both. No wasm scheduler or semaphore symbols are present in the native binaries. Both native fixtures execute successfully; the one-shot sync timing showed no slowdown but is only a smoke check, not a statistical benchmark.Relative to #2197, this PR adds four ordered commits across 19 files (
+892/-70).