I would like to write multithreaded WASM using Zig. I know that multithreaded WASM can be achieved by spawning multiple Web Workers, then giving them all the same WebAssembly.Memory backed by a SharedArrayBuffer. Workers can synchronize and communicate using atomics.
Questions I have:
- What about the stack space per thread? Since all threads use the same memory, their stacks must not overlap. How do I control this?
- Are there any synchronization primitives built-in that can help me, or must I handroll all of it? (thinking mutexes, etc.)
- What things are thread safe? Is the wasm allocator thread safe? If not, do I need to wrap allocations in my own mutex?