endless_loop.cpp 686 B

12345678910111213141516171819202122232425262728
  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/continuation.hpp>
  8. namespace ctx = boost::context;
  9. ctx::continuation foo( ctx::continuation && c) {
  10. do {
  11. std::cout << "foo\n";
  12. } while ( ( c = c.resume() ) );
  13. return std::move( c);
  14. }
  15. int main() {
  16. ctx::continuation c = ctx::callcc( foo);
  17. do {
  18. std::cout << "bar\n";
  19. } while ( ( c = c.resume() ) );
  20. std::cout << "main: done" << std::endl;
  21. return EXIT_SUCCESS;
  22. }