Hi :)
I am exploring how a module could make use of threads on the host side and was thinking of the following scenario:
Is something like this possible in general?
I have been trying to implement something into this direction, but could not quite get it to work so far. I have so far been defining host functions via linker.func_wrap(...)
and accessing anything I needed via the Caller
available within the host function and have difficulties figuring out how I would configure the linker and start up the different module instances.
If this the above scenario is doable, could you please give me some advice of how I would configure the linker for this and how the host function would look?
Thanks a lot! :)
I think you're more-or-less describing the current state of the wasi-threads proposal (it's very experimental), and the implementation in Wasmtime might be of interest to you as it's doing what you're describing I believe
Thank you for the pointer :)
If I am reading the code correctly, we create a new Store instance for every new module that we create on a call to the host function we define. So the instances can share memory, in spite of not being in the same store?
And, for the modules to share memory, it is sufficient to add the memory to the linker (line 140)? And then all modules which we instantiate via the host function will have access to it? Is it because they are created from the same instance_pre
?
Sort of but not quite. It's correct that multiple stores are used, one per thread, and that memory is shared. The detail though is that the memory is a SharedMemory
and therefore safe to transfer across threads and additionally independent from a store. This is a form of shared memory multithreading for the wasm module itself, which may or may not be what you're looking for. Shared memory multithreading in wasm requires a fair bit of cooperation with the module in question.
I see. Will try to implement it following the example you linked to and will see how it goes. Thank you! This has been a great help :)
Last updated: Dec 23 2024 at 13:07 UTC