!7 p-experiment { print("Result: "+ callHibernatable(f serve, f reversedString)); } sclass HibernationFuture { new Flag done; O value; Runnable continuation; void setContinuation(Runnable r) { synchronized(done) { if (!done.isUp()) ret with continuation = r; } callF(r); } void setValue(O value) { synchronized(done) { if (done.isUp()) fail("setValue called twice"); this.value = value; done.raise(); } callF(continuation); } } static O callHibernatable(O f1, O f2) { O result; try { result = callF(f1); } catch (RuntimeException e) { Throwable e2 = innerException(e); if (!e2 instanceof HibernatingTheThread) throw rethrow(e); HibernatingTheThread h = cast e2; } ret callF(f2, result); } svoid normalFunction1() { print("finished"); } svoid hibernatingFunction1() { HibernatingTheThread e = new(r { print("finished after hibernation"); }); doLater(1000, e); throw e; } sS aFunction(bool hibernate) { if (hibernate) { print("Hibernating for 1s..."); HibernatingTheThread e = new(func -> S { ret "finished"; }); doLater(1000, e); throw e; } else ret "hello"; } sclass HibernatingTheThread extends QuickException implements Runnable { HibernationFuture future; Flag done; O code; // runnable or F0 O continuation; // runnable or vf1 *() {} *(O *code) {} public void run() { callF(continuation, callF(code)); } }