Commit df650572 authored by Xavier Thompson's avatar Xavier Thompson

examples/: Adapt to new exception propagation

parent 0e135934
...@@ -18,51 +18,46 @@ Task<void> hello(int id) { ...@@ -18,51 +18,46 @@ Task<void> hello(int id) {
co_return; co_return;
} }
Task<void> fail() { Task<void> fail(int delay) {
volatile int n = fibo(delay);
(void) n;
throw std::exception(); throw std::exception();
co_return; co_return;
} }
Join<void> fail_join() { Join<void> fail_join(int delay = 0) {
co_await fork(fail()); co_await fork(fail(delay));
} }
Join<void> join_sync(int max) { Join<void> join_sync(int max) {
for (int id = 0; id < max; id++) { for (int id = 0; id < max; id++) {
co_await fork(hello(id)); co_await fork(hello(id));
} }
try { co_await fork(fail_join());
co_await fork(fail_join()); LOG(" ... fork(fail_join()) did not throw (stolen continuation)");
LOG(" ... fork(fail_join()) did not throw (stolen continuation)");
} catch(std::exception &) {
LOG(" ... fork(fail_join()) did throw, rethrowing");
throw;
}
LOG(" ... sync()"); LOG(" ... sync()");
try co_await Sync();
{ LOG(" ... ERROR sync() did not throw");
co_await Sync();
LOG(" ... ERROR sync() did not throw");
} catch(std::exception &) {
LOG(" ... OK sync() did throw, rethrowing");
throw;
}
} }
Join<void> join_no_sync(int max) { Join<void> join_no_sync(int max) {
for (int id = 0; id < max; id++) { for (int id = 0; id < max; id++) {
co_await fork(hello(id)); co_await fork(hello(id));
} }
try { co_await fork(fail_join());
co_await fork(fail_join()); LOG(" ... fork(fail_join()) did not throw (stolen continuation)");
LOG(" ... fork(fail_join()) did not throw (stolen continuation)");
} catch(std::exception &) {
LOG(" ... fork(fail_join()) did throw, rethrowing");
throw;
}
LOG(" ... join_no_sync(%d) is exiting normally", max); LOG(" ... join_no_sync(%d) is exiting normally", max);
} }
Join<void> join_infinite_fork_loop() {
co_await fork(fail_join(25));
LOG(" ... fork(fail_join()) did not throw (stolen continuation)");
LOG(" ... now looping forever");
for (int id = 0; ; id++) {
co_await fork(hello(id));
}
}
Root root_sync(int max) { Root root_sync(int max) {
try { try {
LOG(">>> join_sync(%d)", max); LOG(">>> join_sync(%d)", max);
...@@ -83,11 +78,21 @@ Root root_no_sync(int max) { ...@@ -83,11 +78,21 @@ Root root_no_sync(int max) {
} }
} }
Root root_infinite_fork_loop() {
try {
LOG(">>> join_infinite_fork_loop()");
co_await join_infinite_fork_loop();
} catch(std::exception &) {
LOG("OK join_infinite_fork_loop() did throw eventually\n");
}
}
int main() { int main() {
root_sync(0).call(); root_sync(0).call();
root_sync(20).call(); root_sync(20).call();
root_no_sync(0).call(); root_no_sync(0).call();
root_no_sync(20).call(); root_no_sync(20).call();
root_infinite_fork_loop().call();
puts("done"); puts("done");
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment