| 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 | typedef boost::coroutines::symmetric_coroutine< void > coro_t; |
| 15 | |
| 16 | coro_t::call_type * c1 = 0; |
| 17 | coro_t::call_type * c2 = 0; |
| 18 | |
| 19 | void foo( coro_t::yield_type & yield) |
| 20 | { |
| 21 | std::cout << "foo1"<< std::endl; |
| 22 | yield( * c2); |
| 23 | std::cout << "foo2"<< std::endl; |
| 24 | yield( * c2); |
| 25 | std::cout << "foo3"<< std::endl; |
| 26 | } |
| 27 | |
| 28 | void bar( coro_t::yield_type & yield) |
| 29 | { |
| 30 | std::cout << "bar1"<< std::endl; |
| 31 | yield( * c1); |
| 32 | std::cout << "bar2"<< std::endl; |
| 33 | yield( * c1); |
| 34 | std::cout << "bar3"<< std::endl; |
| 35 | } |
| 36 | |
| 37 | int main( int argc, char * argv[]) |
| 38 | { |
| 39 | coro_t::call_type coro1( foo); |
| 40 | coro_t::call_type coro2( bar); |
| 41 | c1 = & coro1; |
| 42 | c2 = & coro2; |
| 43 | coro1(); |
| 44 | std::cout << "Done"<< std::endl; |
| 45 | |
| 46 | return EXIT_SUCCESS; |
| 47 | } |
| 48 |
