MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / main

Function main

examples/interrupt.cc:38–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36}
37
38int main() {
39 // Enable interruptible code via `Config` and then create an interrupt
40 // handle which we'll use later to interrupt running code.
41 Config config;
42 config.epoch_interruption(true);
43 Engine engine(std::move(config));
44 Store store(engine);
45 store.context().set_epoch_deadline(1);
46
47 // Compile and instantiate a small example with an infinite loop.
48 auto wat = readFile("examples/interrupt.wat");
49 Module module = Module::compile(engine, wat).unwrap();
50 Instance instance = Instance::create(store, module, {}).unwrap();
51 Func run = std::get<Func>(*instance.get(store, "run"));
52
53 // Spin up a thread to send us an interrupt in a second
54 std::thread t([engine{std::move(engine)}]() {
55 std::this_thread::sleep_for(std::chrono::seconds(1));
56 std::cout << "Interrupting!\n";
57 engine.increment_epoch();
58 });
59
60 std::cout << "Entering infinite loop ...\n";
61 auto err = run.call(store, {}).err();
62 auto &trap = std::get<Trap>(err.data);
63
64 std::cout << "trap: " << trap.message() << "\n";
65 t.join();
66}

Callers

nothing calls this directly

Calls 13

readFileFunction · 0.70
compileFunction · 0.50
createFunction · 0.50
epoch_interruptionMethod · 0.45
set_epoch_deadlineMethod · 0.45
contextMethod · 0.45
unwrapMethod · 0.45
getMethod · 0.45
increment_epochMethod · 0.45
errMethod · 0.45
callMethod · 0.45
messageMethod · 0.45

Tested by

no test coverage detected