bytecodealliance / wasm-micro-runtime

WebAssembly Micro Runtime (WAMR)
Apache License 2.0
4.98k stars 628 forks source link

Modules with different native symbols #3830

Open tvili999 opened 1 month ago

tvili999 commented 1 month ago

Thank you for your awesome work!

I'd like to ask some directions in an issue I cannot solve. I have a runtime that runs many modules at the same time in different threads. I initialize the runtime with wasm_runtime_init and register some native modules with wasm_runtime_register_natives.

Then in the threads, I run wasm_runtime_init_thread_env, and load/execute modules separately.

But now we need to run them with two sets of native symbols, so ModuleA needs nativeSymbolsA, and ModuleB needs nativeSymbolsB as native symbols. They both need to run at the same time from the same process, but from different threads. How could I achieve this?

Thank you!

TianlongLiang commented 1 month ago

IIUC, you want to separate those two sets of native symbols right? You can consider wasm_runtime_init, then in one thread's critical section register_natives the first set of symbols, load the first module(unregister the first set of symbols if there are name conflicting or you don't want module B potentially use the first set of native symbols), and in another thread's critical section, register_natives the second set of symbols and load the second module. By critical section I mean you need to use lock or other sync primitives you prefer to make sure the register-load-unregister process happens atomically