• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <tuple>
10 
11 #include <boost/context/fiber.hpp>
12 
13 namespace ctx = boost::context;
14 
f1(ctx::fiber && f)15 ctx::fiber f1( ctx::fiber && f) {
16     std::cout << "f1: entered first time"  << std::endl;
17     f = std::move( f).resume();
18     std::cout << "f1: entered second time" << std::endl;
19     f = std::move( f).resume();
20     std::cout << "f1: entered third time" << std::endl;
21     return std::move( f);
22 }
23 
f2(ctx::fiber && f)24 ctx::fiber f2( ctx::fiber && f) {
25     std::cout << "f2: entered" << std::endl;
26     return std::move( f);
27 }
28 
main()29 int main() {
30     ctx::fiber f{ f1 };
31     f = std::move( f).resume();
32     std::cout << "f1: returned first time" << std::endl;
33     f = std::move( f).resume();
34     std::cout << "f1: returned second time" << std::endl;
35     f = std::move( f).resume_with( f2);
36     std::cout << "f1: returned third time" << std::endl;
37 
38     std::cout << "main: done" << std::endl;
39 
40     return EXIT_SUCCESS;
41 }
42