WasmEdge / wasmedge-rust-sdk

Embed WasmEdge functions in a Rust host app
Apache License 2.0
30 stars 15 forks source link

Is it able to use a vm instance to run multiple function tasks? #89

Open ActivePeter opened 1 year ago

L-jasmine commented 1 year ago

The VM instance cannot simultaneously run multiple function tasks; it can execute multiple function tasks sequentially. This is because, during the execution of wasm, changes to some data in the VM may occur through host functions. Therefore, a function, while executing, requires a mutable reference to the VM.

ActivePeter commented 1 year ago

How to implement the concurrency through wasm?

ActivePeter commented 1 year ago

each task spawn a VM Instance?

L-jasmine commented 1 year ago

In most cases, a VM Instance includes both wasm and the host module. The execution of wasm often changes the state of the host module. If you ensure that your host module is reusable, you can retain this VM Instance after wasm execution, then register new wasm into it for subsequent runs. Otherwise, it's better to create a new VM instance each time.