]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fiber/examples/join.cpp
2 // Copyright Oliver Kowalke 2013.
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)
13 #include <boost/fiber/all.hpp>
20 boost::fibers::fiber::id this_id
= boost::this_fiber::get_id();
21 for ( int i
= 0; i
< 5; ++i
)
24 std::cout
<< "fiber " << this_id
<< " fn1: increment value1: " << value1
<< std::endl
;
25 boost::this_fiber::yield();
27 std::cout
<< "fiber " << this_id
<< " fn1: returns" << std::endl
;
30 void fn2( boost::fibers::fiber
& f
)
32 boost::fibers::fiber::id this_id
= boost::this_fiber::get_id();
33 for ( int i
= 0; i
< 5; ++i
)
36 std::cout
<< "fiber " << this_id
<< " fn2: increment value2: " << value2
<< std::endl
;
39 boost::fibers::fiber::id id
= f
.get_id();
40 std::cout
<< "fiber " << this_id
<< " fn2: joins fiber " << id
<< std::endl
;
42 std::cout
<< "fiber " << this_id
<< " fn2: joined fiber " << id
<< std::endl
;
44 boost::this_fiber::yield();
46 std::cout
<< "fiber " << this_id
<< " fn2: returns" << std::endl
;
53 boost::fibers::fiber
f1( fn1
);
54 boost::fibers::fiber
f2( fn2
, std::ref( f1
) );
58 std::cout
<< "done." << std::endl
;
62 catch ( std::exception
const& e
)
63 { std::cerr
<< "exception: " << e
.what() << std::endl
; }
65 { std::cerr
<< "unhandled exception" << std::endl
; }