aboutsummaryrefslogtreecommitdiff
path: root/lib/std/Thread.zig
diff options
context:
space:
mode:
authorLuuk de Gram <luuk@degram.dev>2023-06-26 19:10:34 +0200
committerLuuk de Gram <luuk@degram.dev>2023-06-26 20:00:58 +0200
commit87b8a0567b0f54415aeecd879d3f1a4e12014d22 (patch)
tree77cea5728d61fd701009a40e6ac0c70ce282c69a /lib/std/Thread.zig
parente06ab1b0107e8a6a1720703a6df0f61f535b5e5a (diff)
downloadzig-87b8a0567b0f54415aeecd879d3f1a4e12014d22.tar.gz
zig-87b8a0567b0f54415aeecd879d3f1a4e12014d22.zip
default to single-threaded for WebAssembly
When targeting WebAssembly, we default to building a single-threaded build as threads are still experimental. The user however can enable a multi- threaded build by specifying '-fno-single-threaded'. It's a compile-error to enable this flag, but not also enable shared-memory.
Diffstat (limited to 'lib/std/Thread.zig')
-rw-r--r--lib/std/Thread.zig4
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig
index b8cc8c8869..99e2feb4cf 100644
--- a/lib/std/Thread.zig
+++ b/lib/std/Thread.zig
@@ -919,6 +919,10 @@ const WasiThreadImpl = struct {
/// Bootstrap procedure, called by the host environment after thread creation.
export fn wasi_thread_start(tid: i32, arg: *Instance) void {
+ if (builtin.single_threaded) {
+ // ensure function is not analyzed in single-threaded mode
+ return;
+ }
__set_stack_pointer(arg.thread.memory.ptr + arg.stack_offset);
__wasm_init_tls(arg.thread.memory.ptr + arg.tls_offset);
@atomicStore(u32, &WasiThreadImpl.tls_thread_id, @intCast(tid), .SeqCst);