// Resume Across Other Handler #include #include #include #include exception fixup_exception { int & fixup; }; vtable(fixup_exception) fixup_vt; exception not_raised_exception { int & fixup; }; // Using a global value to allow hoisting (and avoid thunks). unsigned int frames; void nounwind_other(unsigned int dummy) { if (frames) { frames -= 1; try { nounwind_other(42); // Always false, but prevents recursion elimination. if (-1 == frames) printf("~"); } catchResume (not_raised_exception * ex) { ex->fixup = frames + 42; } } else { int fixup = dummy; throwResume (fixup_exception){&fixup_vt, fixup}; } } int main(int argc, char * argv[]) { unsigned int times = 1; unsigned int total_frames = 1; if (1 < argc) { times = strto(argv[1], 0p, 10); } if (2 < argc) { total_frames = strto(argv[2], 0p, 10); } frames = total_frames; Time start_time = timeHiRes(); for (int count = 0 ; count < times ; ++count) { try { nounwind_other(42); } catchResume (fixup_exception * ex) { ex->fixup = total_frames + 42; } } Time end_time = timeHiRes(); sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.); }