Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Are module instances thread-safe? #93

Open
jonathanmarvens opened this issue Jan 25, 2024 · 1 comment
Open

Are module instances thread-safe? #93

jonathanmarvens opened this issue Jan 25, 2024 · 1 comment
Labels
question Further information is requested

Comments

@jonathanmarvens
Copy link

jonathanmarvens commented Jan 25, 2024

I asked this question in the wasm2c project, but I’m also curious what w2c2’s semantics are when it comes to this type of usage.

Basically, is it undefined behavior to instantiate a module in thread A and then call into the instance in threads B, C, D, etc.? We can assume only one thread ever calls into the instance at any time.

I’m currently using a runtime in which this behavior is supported and well-defined, but I want to switch to either wasm2c or w2c2.

For the sake of understanding what this project supports (or at least intends to support), we can ignore the fact that pre-C11 multithreading is undefined and assume the compiler enforces a well-defined C11-like memory model anyway.

Thank you!

@turbolent turbolent added the question Further information is requested label Feb 4, 2024
@turbolent
Copy link
Owner

is it undefined behavior to instantiate a module in thread A and then call into the instance in threads B, C, D, etc.? We can assume only one thread ever calls into the instance at any time.

(from the linked issue:)

is it okay if a module is instantiated by thread A, and then (after that has provably completed) thread B calls an exported function from that module instance, and then (after that has provably completed) thread C calls an exported function from the same module instance?

AFAICS, module instances do not have per-thread state, so as long as access is properly separated, such a usage should work. Please let me know if you are running into problems

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants