Stream: wasmtime

Topic: Various usability questions


view this post on Zulip Jakub Hlusička (May 07 2020 at 21:42):

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 Strings in version 0.8.0.

view this post on Zulip Alex Crichton (May 07 2020 at 21:49):

@Jakub Hlusička oh dear that's a bug, Func closures extracted should not be Send or Sync

view this post on Zulip Alex Crichton (May 07 2020 at 21:49):

otherwise interface types are currently not implemented in wasmtime so you can't pass a string right now

view this post on Zulip Alex Crichton (May 07 2020 at 21:49):

you'll need to manually copy in/out of wasm memory

view this post on Zulip Alex Crichton (May 07 2020 at 21:49):

We hope to implement it in the near future though!

view this post on Zulip Alex Crichton (May 07 2020 at 21:51):

hm although testing now Func::get return values aren't Send/Sync for me?

view this post on Zulip Alex Crichton (May 07 2020 at 21:51):

this may have been something which accidentally regressed which we ended up fixing recently though

view this post on Zulip Jakub Hlusička (May 07 2020 at 21:53):

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

view this post on Zulip Alex Crichton (May 07 2020 at 21:53):

oh so not always, in that case it returns impl Fn() which means the compiler is still auto-inferring Send/Sync

view this post on Zulip Alex Crichton (May 07 2020 at 21:53):

I don't believe the documentation renders the Send/Sync inference right now

view this post on Zulip Jakub Hlusička (May 07 2020 at 21:58):

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.

view this post on Zulip Alex Crichton (May 07 2020 at 22:09):

Ah yes currently you can't share wasm instances across threads

view this post on Zulip Alex Crichton (May 07 2020 at 22:09):

(or, rather, you'll never be able to do that)

view this post on Zulip Alex Crichton (May 07 2020 at 22:09):

eventually we'll support two instances sharing a memory across threads

view this post on Zulip Alex Crichton (May 07 2020 at 22:09):

but we don't have support for that yet

view this post on Zulip Jakub Hlusička (May 07 2020 at 22:11):

Alright, thank you for the help! Have a nice day.


Last updated: Dec 23 2024 at 14:03 UTC