simple.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright Oliver Kowalke 2009.
  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 <boost/coroutine/all.hpp>
  6. #include <cstdlib>
  7. #include <iostream>
  8. #include <boost/bind.hpp>
  9. typedef boost::coroutines::symmetric_coroutine< void > coro_t;
  10. coro_t::call_type * c1 = 0;
  11. coro_t::call_type * c2 = 0;
  12. void foo( coro_t::yield_type & yield)
  13. {
  14. std::cout << "foo1" << std::endl;
  15. yield( * c2);
  16. std::cout << "foo2" << std::endl;
  17. yield( * c2);
  18. std::cout << "foo3" << std::endl;
  19. }
  20. void bar( coro_t::yield_type & yield)
  21. {
  22. std::cout << "bar1" << std::endl;
  23. yield( * c1);
  24. std::cout << "bar2" << std::endl;
  25. yield( * c1);
  26. std::cout << "bar3" << std::endl;
  27. }
  28. int main( int argc, char * argv[])
  29. {
  30. coro_t::call_type coro1( foo);
  31. coro_t::call_type coro2( bar);
  32. c1 = & coro1;
  33. c2 = & coro2;
  34. coro1();
  35. std::cout << "Done" << std::endl;
  36. return EXIT_SUCCESS;
  37. }