Hi all, been digging into Wasmtime and am excited. I'm trying to figure out whether something is in principle doable, or whether I'd be fighting the system too much. Is it possible for a module to pause/yield its own execution, have its Store be written, and then have the host restart it from the point where it was in execution? The goal is just to enable async/await semantics from inside modules.
Apologies if this is the wrong place to post--just feeling my way around Zulip today.
I guess https://github.com/WebAssembly/stack-switching is similar to what you want to do, or https://emscripten.org/docs/porting/asyncify.html will help you if Emscripten is available.
Yes, stack-switching definitely matches what I want. What is its status...still just a proposal?
Unfortunately, yes. I don't know any implementation of it.
I think what you describe is already how host function calls work, I mean, your wasm can call a host function. This halts the wasm vm and lets the host do whatever the function does, when the function is done the return value is written to wasm memory and then the wasm vm gets resumed with a pointer to the correct place in memory where the new data was written, at least that's how wasi_preview1 worked
Ramon Klass said:
I think what you describe is already how host function calls work, I mean, your wasm can call a host function. This halts the wasm vm and lets the host do whatever the function does, when the function is done the return value is written to wasm memory and then the wasm vm gets resumed with a pointer to the correct place in memory where the new data was written, at least that's how wasi_preview1 worked
Thanks, I think this is exactly what I was looking for. If anyone can confirm or show a quick example, would be amazing.
Yes, stack-switching definitely matches what I want. What is its status...still just a proposal?
Unfortunately, yes. I don't know any implementation of it.
FWIW I am one of the coauthors of typed continuations proposal for stack switching. We have an implementation of it in Wasmtime, that I intend to announce at the next stacks subgroup meeting. I am hopeful that we can advance the phase of the stack switching proposal later this year.
If you use the async feature (read these docs carefully!) of wasmtime then host-implemented functions can themselves be async. The asyncness is invisible to the guest environment but it allows the host to perform e.g. async I/O
8 messages were moved here from #general > new streams by Alex Crichton.
Timothy Galebach said:
Is it possible for a module to pause/yield its own execution, have its Store be written, and then have the host restart it from the point where it was in execution? T
When you say "have its Store
be written", do you mean like actually serialized and written out to disk? Wasmtime does not support this kind of snapshotting and rehydration at this time. It is a very big feature to implement.
But in general, Wasmtime's async support lets you pause Wasm execution at any host call, epoch interrupt, or when fuel runs out. You can then resume execution whenever you'd like. But the Wasm instance, though paused, is still resident in the process's memory and cannot be written to disk or resumed in a different process or anything like that.
fitzgen (he/him) said:
Timothy Galebach said:
Is it possible for a module to pause/yield its own execution, have its Store be written, and then have the host restart it from the point where it was in execution? T
When you say "have its
Store
be written", do you mean like actually serialized and written out to disk? Wasmtime does not support this kind of snapshotting and rehydration at this time. It is a very big feature to implement.But in general, Wasmtime's async support lets you pause Wasm execution at any host call, epoch interrupt, or when fuel runs out. You can then resume execution whenever you'd like. But the Wasm instance, though paused, is still resident in the process's memory and cannot be written to disk or resumed in a different process or anything like that.
Thanks, that's exactly what I was asking. I didn't mean writing to disk--I just meant writing to the Store's memory, which you answered.
I've seen the fuel calls and epoch interrupt...could you point me to documentation of using an arbitrary host call to pause Wasm execution?
"Pausing" execution is the async feature. If an async host call returns a pending future, that gets (transparently to the guest) passed back down the stack to the intial async call into the guest, which effectively pauses the guest until the future is ready
To summarize, all you have to do to pause a Wasm execution at a host call is pause in the implementation of that host function.
Last updated: Dec 23 2024 at 12:05 UTC