1 2 // Copyright Oliver Kowalke 2016. 3 // Distributed under the Boost Software License, Version 1.0. 4 // (See accompanying file LICENSE_1_0.txt or copy at 5 // http://www.boost.org/LICENSE_1_0.txt) 6 7 #include <cstdlib> 8 #include <iostream> 9 #include <list> 10 11 #include <boost/context/fiber.hpp> 12 13 namespace ctx = boost::context; 14 main()15int main() { 16 ctx::fiber f1, f2, f3; 17 f3 = ctx::fiber{[&](ctx::fiber && f)->ctx::fiber{ 18 f2 = std::move( f); 19 for (;;) { 20 std::cout << "f3\n"; 21 f2 = f1.resume(); 22 } 23 return {}; 24 }}; 25 f2 = ctx::fiber{[&](ctx::fiber && f)->ctx::fiber{ 26 f1 = std::move( f); 27 for (;;) { 28 std::cout << "f2\n"; 29 f1 = f3.resume(); 30 } 31 return {}; 32 }}; 33 f1 = ctx::fiber{[&](ctx::fiber && /*main*/)->ctx::fiber{ 34 for (;;) { 35 std::cout << "f1\n"; 36 f3 = f2.resume(); 37 } 38 return {}; 39 }}; 40 f1.resume(); 41 42 std::cout << "main: done" << std::endl; 43 return EXIT_SUCCESS; 44 } 45