]>
Commit | Line | Data |
---|---|---|
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 <iostream> | |
9 | #include <memory> | |
10 | #include <string> | |
11 | #include <thread> | |
12 | ||
7c673cae FG |
13 | #include <boost/intrusive_ptr.hpp> |
14 | ||
15 | #include <boost/fiber/all.hpp> | |
16 | ||
17 | inline | |
b32b8144 FG |
18 | void fn( std::string const& str, int n) { |
19 | for ( int i = 0; i < n; ++i) { | |
7c673cae FG |
20 | std::cout << i << ": " << str << std::endl; |
21 | boost::this_fiber::yield(); | |
22 | } | |
23 | } | |
24 | ||
b32b8144 FG |
25 | int main() { |
26 | try { | |
7c673cae FG |
27 | boost::fibers::fiber f1( fn, "abc", 5); |
28 | std::cerr << "f1 : " << f1.get_id() << std::endl; | |
7c673cae | 29 | f1.join(); |
7c673cae FG |
30 | std::cout << "done." << std::endl; |
31 | ||
32 | return EXIT_SUCCESS; | |
b32b8144 FG |
33 | } catch ( std::exception const& e) { |
34 | std::cerr << "exception: " << e.what() << std::endl; | |
35 | } catch (...) { | |
36 | std::cerr << "unhandled exception" << std::endl; | |
7c673cae | 37 | } |
7c673cae FG |
38 | return EXIT_FAILURE; |
39 | } |