-
Notifications
You must be signed in to change notification settings - Fork 256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi-threading and Atomics #296
Comments
The current state is that the WebAssembly core spec for threads is designed around Web Worker-style threading, the current thinking is that this model isn't suitable for use outside the Web or similar runtimes. See the following issues for some background discussion: WebAssembly/threads#8 When the core spec adds better support for threading in non-Web environments, I expect we'll quickly add WASI APIs for creating and managing threads. |
Those threads mostly concern the future native threading proposal, but in WebAssembly/threads#138, @lukewagner wrote,
I agree with Luke's thinking there that in principle there is nothing stopping WASI from having a standard API for creating and manipulating threads using the current proposal. Is there a WASI design goal that would prevent that from working, or is it just a matter of not spending time on a solution based on the current proposal when we expect a better proposal to come along eventually? |
I'm not aware of any conflicts with design goals. It's mainly about not wanting to get too far away from where we expect the core spec will go, and an optimistic assumption that the work to enable native threads will happen on a reasonable timeframe. A key question is: is there one wasm instance per thread (like workers do), or just one wasm instance that can be running multiple threads (as the "native" thread proposals typically suggest)? That affects whether or not we run the wasm start function on thread creation. And it affects whether globals are thread-local or not -- and since we use a global for the linear-memory stack pointer, if it isn't thread-local we need to do something different. Another question is, if a module has exports or registers callbacks and gets called on a new thread, if it needs a linear-memory stack, when does it allocate the new stack? That's a question for native threads too, though I imagine they'll need a different answer. |
any discuss result, I prefer one wasm instance per thread (like workers do), and the native one can implement base on that, can we use multiple memory to sharing wasm instance across threads? for thread
|
Typical shared-memory programming models have a single address space that all threads share, which in general would not be compatible with multiple wasm memories.
Yes, thead-local variables typically do use shared memory. |
From my point of view, webwoker are more like a process than a thread, even though we name it as a thread. Because of webassembly are inherently isolation of each webassembly/webworker instance, the sharedmemory also need postMessage to getting them to be shared, from this point of view, in web there is no native threads at all, they are all process。
|
Hello, I personally don't need the full pthread library support. So is there any reason not to be able to compile the C library with the shared memory model (ie. what clang's driver option |
The C library itself depends on pthread support to make itself thread-safe when compiled with the shared memory model. |
Hi, I really excited about WASI and what it's trying to achieve. I looked around for this, but couldn't find any mention of it. What is the status of multi-threading and Atomics in WASI? I saw that Chrome added support to threading in WASM. I just was curious about its status in WASI, and if it's not there yet how long down the line can we expect to have it there?
Thank you
The text was updated successfully, but these errors were encountered: