Skip to main content

Module threads

Module threads 

Source
Expand description

Real threads for guests (wasi-threads): a module built for wasm32-wasip1-threads imports a shared memory (env.memory) and wasi.thread-spawn(start_arg) -> tid, and exports wasi_thread_start(tid, start_arg). Each spawned thread is an OS thread with its own store and its own instance of the same module, sharing the memory; its _initialize doesn’t run (the memory is already set up).

Worker threads compute and read: the WASI subset, gasm.time_ms, gasm.log, gasm.has and the assets (a copy taken when the thread starts) work there; the other gasm imports (video, audio, input, GPU, network, storage) belong to the main thread and do nothing on a worker. A trap or proc_exit on any thread ends the whole game (wasi-threads), seen by the runner after the frame. Threads aren’t deterministic: headless runs allow none unless --threads says so (thread-spawn then fails, as when the limit is reached), so hashes stay comparable. See design/threads.md, part B.

Structs§

Threads
What spawning needs, shared by every thread of a game.

Enums§

ThreadEnd
How a thread ended the game, for the main thread to report.

Functions§

add_to_linker
wasi.thread-spawn, for modules that import it.
shared_memory_import
The module’s shared memory import (env.memory), if it has one: its type.