| 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 | void first( boost::coroutines::asymmetric_coroutine< void >::push_type & sink) |
| 15 | { |
| 16 | std::cout << "started first! "; |
| 17 | for ( int i = 0; i < 10; ++i) |
| 18 | { |
| 19 | sink(); |
| 20 | std::cout << "a"<< i; |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | void second( boost::coroutines::asymmetric_coroutine< void >::push_type & sink) |
| 25 | { |
| 26 | std::cout << "started second! "; |
| 27 | for ( int i = 0; i < 10; ++i) |
| 28 | { |
| 29 | sink(); |
| 30 | std::cout << "b"<< i; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | int main( int argc, char * argv[]) |
| 35 | { |
| 36 | { |
| 37 | boost::coroutines::asymmetric_coroutine< void >::pull_type source1( boost::bind( f: first, a1: _1) ); |
| 38 | boost::coroutines::asymmetric_coroutine< void >::pull_type source2( boost::bind( f: second, a1: _1) ); |
| 39 | while ( source1 && source2) { |
| 40 | source1(); |
| 41 | std::cout << " "; |
| 42 | source2(); |
| 43 | std::cout << " "; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | std::cout << "\nDone"<< std::endl; |
| 48 | |
| 49 | return EXIT_SUCCESS; |
| 50 | } |
| 51 |
