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