]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fiber/examples/asio/exchange.cpp
1 // Copyright Arnaud Kapp, Oliver Kowalke 2016
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
10 #include <boost/asio.hpp>
12 #include <boost/fiber/all.hpp>
13 #include "round_robin.hpp"
15 std::shared_ptr
< boost::fibers::unbuffered_channel
< int > > c
;
18 auto io_ptr
= std::make_shared
< boost::asio::io_context
>();
19 boost::fibers::use_scheduling_algorithm
< boost::fibers::asio::round_robin
>( io_ptr
);
20 boost::fibers::fiber([io_ptr
](){
21 for ( int i
= 0; i
< 10; ++i
) {
22 std::cout
<< "push " << i
<< std::endl
;
32 auto io_ptr
= std::make_shared
< boost::asio::io_context
>();
33 boost::fibers::use_scheduling_algorithm
< boost::fibers::asio::round_robin
>( io_ptr
);
34 boost::fibers::fiber([io_ptr
](){
37 int i
= c
->value_pop();
38 std::cout
<< "pop " << i
<< std::endl
;
40 } catch ( std::exception
const& e
) {
41 std::cout
<< "exception: " << e
.what() << std::endl
;
49 c
= std::make_shared
< boost::fibers::unbuffered_channel
< int > >();
54 std::cout
<< "done." << std::endl
;