• 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 
10 #include <boost/context/fiber.hpp>
11 
12 namespace ctx = boost::context;
13 
main()14 int main() {
15     int data = 1;
16     ctx::fiber f{
17             [&data](ctx::fiber && f){
18                 std::cout << "entered first time: " << data << std::endl;
19                 data += 2;
20                 f = std::move( f).resume();
21                 std::cout << "entered second time: " << data << std::endl;
22                 return std::move( f);
23             }};
24     f = std::move( f).resume();
25     std::cout << "returned first time: " << data << std::endl;
26     data += 2;
27     f = std::move( f).resume();
28     if ( f) {
29         std::cout << "returned second time: " << data << std::endl;
30     } else {
31         std::cout << "returned second time: execution context terminated" << std::endl;
32     }
33     std::cout << "main: done" << std::endl;
34     return EXIT_SUCCESS;
35 }
36