Replies: 2 comments 4 replies
-
The WASI environment could probably allow many functions to be imported as both shared and non-shared (assuming that these boil down to primitives that could be used concurrently in a native environment). In an MVP solution, producers would need to accept the restrictions on expressivity (esp. on the Web, given the above) and work around them - one possible scheme:
EDIT: see my child comment below for a simpler MVP scheme that doesn't require dispatcher threads As a post-MVP solution (on the Web), we could introduce a mechanism to safely call non-shared functions from shared functions. Taking inspiration from a previous idea by @lukewagner, we could allow non-shared functions to be "wrapped" as shared functions. Wrapped functions would be typed as shared, and calling them would call the underlying non-shared function, with the following restrictions:
One nice thing about this solution is that it can be JS API only. All wrapped functions end up looking to Wasm just like regular callable functions. |
Beta Was this translation helpful? Give feedback.
-
One separate point (and this seems the best existing issue to make it) - the current overview doesn't correctly describe the behaviour of non-shared Wasm state (what about thread local storage?). Shared functions will only have access to the parts of the module marked as shared - e.g. attempting to access a non-shared global from a shared function would be a validation error. So non-shared state can't be used for thread-local storage. Instead, thread-local storage has to be allocated in a shared Wasm linear memory (as already needs to happen with address-taken local variables when compiling C/C++ to Wasm) and the current thread id (as handed out here) is used to address the allocation corresponding to the current thread (I'm told this is similar to how thread local storage works natively, especially in dynamic linking scenarios). A post-MVP extension could add language-level thread-local storage, but we'd need to be careful about the semantics. |
Beta Was this translation helpful? Give feedback.
-
In the engine requirements of
shared
attributes, we ask: "how can we haveshared
imports?" Currently, all imports to WebAssembly modules that are based on WASI or Web APIs would not beshared
, preventing them from being called in a thread. This severely limits thread utility. In previous conversations we have discussed some ideas for solving this — let's use this topic to record them.Beta Was this translation helpful? Give feedback.
All reactions