jump_void.cpp 817 B

1234567891011121314151617181920212223242526272829
  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 <boost/context/fiber.hpp>
  8. namespace ctx = boost::context;
  9. ctx::fiber f1( ctx::fiber && f) {
  10. std::cout << "f1: entered first time" << std::endl;
  11. f = std::move( f).resume();
  12. std::cout << "f1: entered second time" << std::endl;
  13. return std::move( f);
  14. }
  15. int main() {
  16. ctx::fiber f{ f1 };
  17. f = std::move( f).resume();
  18. std::cout << "f1: returned first time" << std::endl;
  19. f = std::move( f).resume();
  20. std::cout << "f1: returned second time" << std::endl;
  21. std::cout << "main: done" << std::endl;
  22. return EXIT_SUCCESS;
  23. }