wasi-threads icon indicating copy to clipboard operation
wasi-threads copied to clipboard

Quesitons about `wasi_thread_spawn` semantics

Open yamt opened this issue 2 years ago • 5 comments

the description of wasi_thread_spawn says:

instantiate the module again — this child instance will be used for the new thread

it isn't obvious to me which module "the module" here is when multiple modules are involved. for example, if module A calls a function imported from module B and the function calls wasi_thread_spawn, which module is it?

also, does instantiate the module again imply that an engine needs to keep an equivalent of wasm-c-api wasm_extern_vec_t or "import object" (i mean importObject argument of WebAssembly.instantiate) for possible wasi_thread_spawn operations?

yamt avatar Dec 06 '22 12:12 yamt

the description of wasi_thread_spawn says:

instantiate the module again — this child instance will be used for the new thread

it isn't obvious to me which module "the module" here is when multiple modules are involved. for example, if module A calls a function imported from module B and the function calls wasi_thread_spawn, which module is it?

also, does instantiate the module again imply that an engine needs to keep an equivalent of wasm-c-api wasm_extern_vec_t or "import object" (i mean importObject argument of WebAssembly.instantiate) for possible wasi_thread_spawn operations?

as i couldn't find a way to determine them reliably, i made them explicitly specified by an embedder for my runtime. https://github.com/yamt/toywasm/blob/ad3c57eaad7f04541c4b4b6f501dcdfe5221919c/lib/wasi_threads.h#L7-L9

yamt avatar Dec 11 '22 15:12 yamt

if module A calls a function imported from module B and the function calls wasi_thread_spawn, which module is it?

I don't think the "multiple linked modules" story is completely figured out. I think this question is similar to the dilemma that wasi-threads faces when attempting to use it in the component model paradigm.

also, does instantiate the module again imply that an engine needs to keep an equivalent of wasm-c-api wasm_extern_vec_t or "import object"

I believe that is correct; e.g., in Wasmtime the linking happens again for each new thread instantiation.

abrown avatar Dec 16 '22 23:12 abrown

@yamt, can we close this now?

abrown avatar Feb 08 '23 02:02 abrown

questions are answered. it seems there is no plan to decide behavior with multiple modules in near future. closing.

yamt avatar Feb 08 '23 05:02 yamt

reopening because it's a real problem, not just a question.

yamt avatar Jul 21 '23 04:07 yamt