]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fiber/examples/simple.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / fiber / examples / simple.cpp
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
7 #include <cstdlib>
8 #include <iostream>
9 #include <memory>
10 #include <string>
11 #include <thread>
12
13 #include <boost/intrusive_ptr.hpp>
14
15 #include <boost/fiber/all.hpp>
16
17 inline
18 void fn( std::string const& str, int n) {
19 for ( int i = 0; i < n; ++i) {
20 std::cout << i << ": " << str << std::endl;
21 boost::this_fiber::yield();
22 }
23 }
24
25 int main() {
26 try {
27 boost::fibers::fiber f1( fn, "abc", 5);
28 std::cerr << "f1 : " << f1.get_id() << std::endl;
29 f1.join();
30 std::cout << "done." << std::endl;
31
32 return EXIT_SUCCESS;
33 } catch ( std::exception const& e) {
34 std::cerr << "exception: " << e.what() << std::endl;
35 } catch (...) {
36 std::cerr << "unhandled exception" << std::endl;
37 }
38 return EXIT_FAILURE;
39 }