Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Store threads #89

Closed
willhausman opened this issue Feb 1, 2022 · 2 comments
Closed

Store threads #89

willhausman opened this issue Feb 1, 2022 · 2 comments

Comments

@willhausman
Copy link

https://github.com/bytecodealliance/wasmtime-dotnet/blob/main/src/Store.cs#L162-L165

Can I get some clarification on this comment? Can I just wrap any operations I use on Store with a lock, or is there something more nefarious at work? If I can just use a lock, is that something this library can handle itself so calling code doesn't get caught unawares by that quirk?

@peterhuene
Copy link
Member

Store (and all objects attached to a store, such as instances) are safe to send to another thread, meaning Store, and its related objects, have no thread-affinity in its internal state. However, that doesn't imply thread safety: a Store, and its related objects, cannot be shared between multiple threads simultaneously as no locking is implemented internally.

Given that Wasmtime currently does not support creating threads from WebAssembly, making Store thread-safe hasn't been a priority for the runtime.

You may try to wrap operations on Store with a lock, but the lock must also be held when executing WebAssembly code (i.e. Function.Invoke) as the execution of WebAssembly itself may alter state relating to the store (keep in mind that host code also might be executed by WebAssembly via the imports given at instantiation). It's probably quite tricky to get right.

For my better understanding, could you perhaps outline your use-case for needing to share a store between threads?

@willhausman
Copy link
Author

Closing in favor of #90. It's the exact use case I'm thinking about, but didn't realize it was already an open issue.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants