circle.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 <list>
  8. #include <boost/context/fiber.hpp>
  9. namespace ctx = boost::context;
  10. int main() {
  11. ctx::fiber f1, f2, f3;
  12. f3 = ctx::fiber{[&](ctx::fiber && f)->ctx::fiber{
  13. f2 = std::move( f);
  14. for (;;) {
  15. std::cout << "f3\n";
  16. f2 = f1.resume();
  17. }
  18. return {};
  19. }};
  20. f2 = ctx::fiber{[&](ctx::fiber && f)->ctx::fiber{
  21. f1 = std::move( f);
  22. for (;;) {
  23. std::cout << "f2\n";
  24. f1 = f3.resume();
  25. }
  26. return {};
  27. }};
  28. f1 = ctx::fiber{[&](ctx::fiber && /*main*/)->ctx::fiber{
  29. for (;;) {
  30. std::cout << "f1\n";
  31. f3 = f2.resume();
  32. }
  33. return {};
  34. }};
  35. f1.resume();
  36. std::cout << "main: done" << std::endl;
  37. return EXIT_SUCCESS;
  38. }