]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/coroutine/example/asymmetric/parallel.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / coroutine / example / asymmetric / parallel.cpp
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 <cstdlib>
8 #include <iostream>
9
10 #include <boost/bind.hpp>
11 #include <boost/coroutine/all.hpp>
12
13 void first( boost::coroutines::asymmetric_coroutine< void >::push_type & sink)
14 {
15 std::cout << "started first! ";
16 for ( int i = 0; i < 10; ++i)
17 {
18 sink();
19 std::cout << "a" << i;
20 }
21 }
22
23 void second( boost::coroutines::asymmetric_coroutine< void >::push_type & sink)
24 {
25 std::cout << "started second! ";
26 for ( int i = 0; i < 10; ++i)
27 {
28 sink();
29 std::cout << "b" << i;
30 }
31 }
32
33 int main( int argc, char * argv[])
34 {
35 {
36 boost::coroutines::asymmetric_coroutine< void >::pull_type source1( boost::bind( first, _1) );
37 boost::coroutines::asymmetric_coroutine< void >::pull_type source2( boost::bind( second, _1) );
38 while ( source1 && source2) {
39 source1();
40 std::cout << " ";
41 source2();
42 std::cout << " ";
43 }
44 }
45
46 std::cout << "\nDone" << std::endl;
47
48 return EXIT_SUCCESS;
49 }