]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/coroutine/example/symmetric/unwind.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / coroutine / example / symmetric / unwind.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 struct X : private boost::noncopyable
14 {
15 X() { std::cout << "X()" << std::endl; }
16 ~X() { std::cout << "~X()" << std::endl; }
17 };
18
19 typedef boost::coroutines::symmetric_coroutine< void > coro_t;
20
21 coro_t::call_type * c1 = 0;
22 coro_t::call_type * c2 = 0;
23
24 void foo( coro_t::yield_type & yield)
25 {
26 X x;
27 std::cout << "foo() entered" << std::endl;
28 yield( * c2);
29 yield( * c2);
30 std::cout << "foo() finished" << std::endl;
31 }
32
33 void bar( coro_t::yield_type & yield)
34 {
35 std::cout << "bar() entered" << std::endl;
36 yield( * c1);
37 std::cout << "bar() finished" << std::endl;
38 }
39
40 int main( int argc, char * argv[])
41 {
42 coro_t::call_type coro1( foo);
43 coro_t::call_type coro2( bar);
44 c1 = & coro1;
45 c2 = & coro2;
46 coro1();
47 std::cout << "Done" << std::endl;
48
49 return EXIT_SUCCESS;
50 }