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.
This commit is contained in:
Luuk de Gram
2023-06-26 19:10:34 +02:00
parent e06ab1b010
commit 87b8a0567b
4 changed files with 30 additions and 8 deletions

View File

@@ -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);