| There don't seem to be many write-ups on this concept. The best reference seems to be existing implementations: Wasmer's implementation of metering[0] just traps when it runs out of fuel. WasmEdge's implementation of interruptibility[1] checks a flag and stops execution if it's set. While neither of these support resuming execution after the deadline, replacing the halt with a call to a signal dispatcher should work. Wasmtime has two different implementations of interrupting execution that both support resuming[2]. The fuel mechanism[3] is deterministic but the epoch mechanism[4] is more performant. If you're free to pick your runtime, I'm sure you could configure Wasmtime into doing what you want. [0]: https://github.com/wasmerio/wasmer/blob/master/lib/middlewar... [1]: https://github.com/WasmEdge/WasmEdge/pull/910 [2]: https://docs.rs/wasmtime/latest/wasmtime/struct.Config.html#... [3]: https://github.com/bytecodealliance/wasmtime/pull/2611 [4]: https://github.com/bytecodealliance/wasmtime/pull/3699 |
6.4 The Cons Counter and Errorset
The cons counter is a useful device for breaking out of program loops. it automatically causes a trap when a certain number of conses have been performed. The counter is turned on by executing count [n], where n is an integer. If n conses are performed before the counter is turned off, a trap will occur and an error diagnostic will be given.