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 first(boost::coroutines::asymmetric_coroutine<void>::push_type & sink)14void 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 second(boost::coroutines::asymmetric_coroutine<void>::push_type & sink)24void 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 main(int argc,char * argv[])34int main( int argc, char * argv[]) 35 { 36 { 37 boost::coroutines::asymmetric_coroutine< void >::pull_type source1( boost::bind( first, _1) ); 38 boost::coroutines::asymmetric_coroutine< void >::pull_type source2( boost::bind( second, _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