• 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 
main()15 int main() {
16     int data = 0;
17     ctx::fiber f{ [&data](ctx::fiber && f) {
18                         std::cout << "f1: entered first time: " << data  << std::endl;
19                         data += 1;
20                         f = std::move( f).resume();
21                         std::cout << "f1: entered second time: " << data  << std::endl;
22                         data += 1;
23                         f = std::move( f).resume();
24                         std::cout << "f1: entered third time: " << data << std::endl;
25                         return std::move( f);
26                     }};
27     f = std::move( f).resume();
28     std::cout << "f1: returned first time: " << data << std::endl;
29     data += 1;
30     f = std::move( f).resume();
31     std::cout << "f1: returned second time: " << data << std::endl;
32     data += 1;
33     f = std::move( f).resume_with([&data](ctx::fiber && f){
34         std::cout << "f2: entered: " << data << std::endl;
35         data = -1;
36         return std::move( f);
37     });
38     std::cout << "f1: returned third time" << std::endl;
39     std::cout << "main: done" << std::endl;
40     return EXIT_SUCCESS;
41 }
42