ontop.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright Oliver Kowalke 2016.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #include <cstdlib>
  6. #include <iostream>
  7. #include <tuple>
  8. #include <boost/context/fiber.hpp>
  9. namespace ctx = boost::context;
  10. int main() {
  11. int data = 0;
  12. ctx::fiber f{ [&data](ctx::fiber && f) {
  13. std::cout << "f1: entered first time: " << data << std::endl;
  14. data += 1;
  15. f = std::move( f).resume();
  16. std::cout << "f1: entered second time: " << data << std::endl;
  17. data += 1;
  18. f = std::move( f).resume();
  19. std::cout << "f1: entered third time: " << data << std::endl;
  20. return std::move( f);
  21. }};
  22. f = std::move( f).resume();
  23. std::cout << "f1: returned first time: " << data << std::endl;
  24. data += 1;
  25. f = std::move( f).resume();
  26. std::cout << "f1: returned second time: " << data << std::endl;
  27. data += 1;
  28. f = std::move( f).resume_with([&data](ctx::fiber && f){
  29. std::cout << "f2: entered: " << data << std::endl;
  30. data = -1;
  31. return std::move( f);
  32. });
  33. std::cout << "f1: returned third time" << std::endl;
  34. std::cout << "main: done" << std::endl;
  35. return EXIT_SUCCESS;
  36. }