implement a webassembly allocator that handles multi-threading #22807
Labels
contributor friendly
This issue is limited in scope and/or knowledge of Zig internals.
enhancement
Solving this issue will likely involve adding new logic or components to the codebase.
os-wasi
standard library
This issue involves writing Zig code for the standard library.
Milestone
Zig Version
0.14.0-dev.3050+d72f3d353
Steps to Reproduce and Observed Behavior
Ever since this commit wasi threads have basically been disabled since we can't create an allocator.
We can make the WasAllocator thread-safe simply by adding a spinlock:
That should protect the allocator state from concurrent modifications. Mutex cannot be used here since the main thread of browsers doesn't allow synchronous wait.
I've put together a demo showing the spinlock approach in the browser. With 16 threads continually allocating and freeing, 100 alloc/free by the main thread doesn't seem to block for too long. The UI remains responsive, which is really the main concern.
It'll be great if we can have functional WebAssembly threads in 0.14.0. Convenient way to show people what Zig is capable of.
Expected Behavior
No comptime error.
The text was updated successfully, but these errors were encountered: