• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 //          Copyright Oliver Kowalke 2009.
3 // Distributed under the Boost Software License, Version 1.0.
4 //    (See accompanying file LICENSE_1_0.txt or copy at
5 //          http://www.boost.org/LICENSE_1_0.txt)
6 
7 #include <boost/coroutine/all.hpp>
8 
9 #include <cstdlib>
10 #include <iostream>
11 
12 #include <boost/bind.hpp>
13 
14 struct X : private boost::noncopyable
15 {
XX16     X() { std::cout << "X()" << std::endl; }
~XX17     ~X() { std::cout << "~X()" << std::endl; }
18 };
19 
20 typedef boost::coroutines::symmetric_coroutine< void >  coro_t;
21 
22 coro_t::call_type * c1 = 0;
23 coro_t::call_type * c2 = 0;
24 
foo(coro_t::yield_type & yield)25 void foo( coro_t::yield_type & yield)
26 {
27     X x;
28     std::cout << "foo() entered" << std::endl;
29     yield( * c2);
30     yield( * c2);
31     std::cout << "foo() finished" << std::endl;
32 }
33 
bar(coro_t::yield_type & yield)34 void bar( coro_t::yield_type & yield)
35 {
36     std::cout << "bar() entered" << std::endl;
37     yield( * c1);
38     std::cout << "bar() finished" << std::endl;
39 }
40 
main(int argc,char * argv[])41 int main( int argc, char * argv[])
42 {
43     coro_t::call_type coro1( foo);
44     coro_t::call_type coro2( bar);
45     c1 = & coro1;
46     c2 = & coro2;
47     coro1();
48     std::cout << "Done" << std::endl;
49 
50     return EXIT_SUCCESS;
51 }
52