endless_loop.cpp 681 B

123456789101112131415161718192021222324252627282930
  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 bar( ctx::fiber && f) {
  10. do {
  11. std::cout << "bar\n";
  12. f = std::move( f).resume();
  13. } while ( f);
  14. return std::move( f);
  15. }
  16. int main() {
  17. ctx::fiber f{ bar };
  18. do {
  19. std::cout << "foo\n";
  20. f = std::move( f).resume();
  21. } while ( f);
  22. std::cout << "main: done" << std::endl;
  23. return EXIT_SUCCESS;
  24. }