Hello,
I have a couple of questions regarding the usage of wasmtime:
First, I have noticed that Instance
is !Send
and !Sync
, but individual Func::get
closures are not. Does that mean I can "extract" a functions via this method and invoke it from multiple threads, simultaneously?
Second, is it currently possible to use String
as a parameter/return type for exported functions? I tried using version 0.16.0, but ran into some compilation errors in the wasmtime
macro, related to the "wasmtime-interface-types" crate. I am able to use String
s in version 0.8.0.
@Jakub Hlusička oh dear that's a bug, Func
closures extracted should not be Send
or Sync
otherwise interface types are currently not implemented in wasmtime so you can't pass a string right now
you'll need to manually copy in/out of wasm memory
We hope to implement it in the near future though!
hm although testing now Func::get
return values aren't Send
/Sync
for me?
this may have been something which accidentally regressed which we ended up fixing recently though
Hmm, I thought I could tell by looking at the function signature: https://docs.rs/wasmtime/0.16.0/wasmtime/struct.Func.html#method.get1
oh so not always, in that case it returns impl Fn()
which means the compiler is still auto-inferring Send/Sync
I don't believe the documentation renders the Send/Sync inference right now
I see, that makes sense. I am intending on using WebAssembly for stateless scripting for a game, and I am trying to make it possible to invoke certain functions exported by a module in parallel. I guess the only option, then, is to instantiate several modules on separate threads, and then distribute the work across those instances.
Ah yes currently you can't share wasm instances across threads
(or, rather, you'll never be able to do that)
eventually we'll support two instances sharing a memory across threads
but we don't have support for that yet
Alright, thank you for the help! Have a nice day.
Last updated: Nov 22 2024 at 16:03 UTC