]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fiber/examples/future.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / fiber / examples / future.cpp
1 #include <cstdlib>
2 #include <exception>
3 #include <functional>
4 #include <iostream>
5 #include <string>
6
7 #include <boost/fiber/all.hpp>
8
9 inline
10 int fn( std::string const& str, int n)
11 {
12 for ( int i = 0; i < n; ++i)
13 {
14 std::cout << i << ": " << str << std::endl;
15 boost::this_fiber::yield();
16 }
17
18 return n;
19 }
20
21 void start()
22 {
23 boost::fibers::future< int > fi(
24 boost::fibers::async(
25 std::bind( fn, "abc", 5) ) );
26 fi.wait();
27 std::cout << "fn() returned " << fi.get() << std::endl;
28 }
29
30 int main()
31 {
32 try
33 {
34 boost::fibers::fiber( start).join();
35 std::cout << "done." << std::endl;
36
37 return EXIT_SUCCESS;
38 }
39 catch ( std::exception const& e)
40 { std::cerr << "exception: " << e.what() << std::endl; }
41 catch (...)
42 { std::cerr << "unhandled exception" << std::endl; }
43 return EXIT_FAILURE;
44 }