Skip to content

Add MultiThread trait and PlatformMutex wrapper - #390

Merged
kateinoigakukun merged 1 commit into
mainfrom
katei/multithread-trait
Jul 27, 2026
Merged

Add MultiThread trait and PlatformMutex wrapper#390
kateinoigakukun merged 1 commit into
mainfrom
katei/multithread-trait

Conversation

@kateinoigakukun

@kateinoigakukun kateinoigakukun commented Jul 27, 2026

Copy link
Copy Markdown
Member

Part of the Embedded Swift support work (#357), split out for incremental review.

Adds a MultiThread package trait (enabled by default) and a PlatformMutex wrapper in Sources/WasmKit/Platform/:

  • With the trait enabled, PlatformMutex is backed by Synchronization.Mutex, forwarding the closure directly so the state type needs no Sendable bound.
  • With the trait disabled, it degrades to plain unsynchronized storage with the same non-copyable shape. This serves single-threaded environments such as bare-metal Embedded Swift targets, where the Synchronization module provides no Mutex. Disabling the trait is a promise that the process runs single-threaded, so the fallback carries @unchecked Sendable.

Interner adopts the wrapper, replacing its direct Mutex use. Its lock property is annotated nonisolated(unsafe) because the single-threaded fallback mutates in place (mutating withLock), which Sendable checking cannot see through. The class conformance itself stays checked.

The CMake build defines MultiThread unconditionally. No functional change with default traits.

@kateinoigakukun
kateinoigakukun force-pushed the katei/multithread-trait branch from 5fbcbe0 to f205064 Compare July 27, 2026 07:17
PlatformMutex is Synchronization.Mutex when the (default-on) MultiThread trait
is enabled and plain unsynchronized storage when disabled for single-threaded
environments; Interner adopts it.
@kateinoigakukun
kateinoigakukun force-pushed the katei/multithread-trait branch from f205064 to 7d559c0 Compare July 27, 2026 07:41
@kateinoigakukun
kateinoigakukun added this pull request to the merge queue Jul 27, 2026
Merged via the queue into main with commit 7f79816 Jul 27, 2026
17 checks passed
@kateinoigakukun
kateinoigakukun deleted the katei/multithread-trait branch July 27, 2026 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant