From 0e24dcd1c4144766ce63e36e44b726aa835356c2 Mon Sep 17 00:00:00 2001 From: q66 Date: Thu, 23 Mar 2017 00:40:17 +0100 Subject: [PATCH] nested coroutine example + use stackpool for dispatcher in bscs --- examples/coroutine2.cc | 32 ++++++++++++++++++++++++++++++++ ostd/concurrency.hh | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/examples/coroutine2.cc b/examples/coroutine2.cc index b8eb29e..d1e432d 100644 --- a/examples/coroutine2.cc +++ b/examples/coroutine2.cc @@ -30,6 +30,28 @@ int main() { generator &gr = dynamic_cast &>(*ctx); writefln("value of cast back generator: %s", gr.value()); + + writeln("-- nested coroutine test --"); + + coroutine c1 = [](auto yield) { + coroutine c2 = [&yield](auto) { + writeln("inside c2 1"); + yield(); + writeln("inside c2 2"); + yield(); + writeln("inside c2 3"); + }; + writeln("inside c1 1"); + c2(); + writeln("inside c1 2"); + }; + writeln("outside 1"); + c1(); + writeln("outside 2"); + c1(); + writeln("outside 3"); + c1(); + writeln("outside exit"); } /* @@ -42,4 +64,14 @@ generated: 25 generator is coroutine: false generator is generator: true value of cast back generator: 5 +-- nested coroutine test -- +outside 1 +inside c1 1 +inside c2 1 +outside 2 +inside c2 2 +outside 3 +inside c2 3 +inside c1 2 +outside exit */ diff --git a/ostd/concurrency.hh b/ostd/concurrency.hh index 4023168..6016feb 100644 --- a/ostd/concurrency.hh +++ b/ostd/concurrency.hh @@ -184,7 +184,7 @@ public: p_stacks(ss, cs), p_dispatcher([this]() { dispatch(); - }, basic_fixedsize_stack{ss}), + }, p_stacks.get_allocator()), p_coros() {}