blob: 8a1dbba15adb432a898c1b3bd5fe755d19d71c96 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
// Copyright Oliver Kowalke 2013.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <cstdlib>
#include <iostream>
#include <stdexcept>
#include <string>
#include <boost/fiber/all.hpp>
typedef boost::fibers::unbuffered_channel< unsigned int > channel_t;
void foo( channel_t & chan) {
chan.push( 1);
chan.push( 1);
chan.push( 2);
chan.push( 3);
chan.push( 5);
chan.push( 8);
chan.push( 12);
chan.close();
}
void bar( channel_t & chan) {
for ( unsigned int value : chan) {
std::cout << value << " ";
}
std::cout << std::endl;
}
int main() {
try {
channel_t chan;
boost::fibers::fiber f1( & foo, std::ref( chan) );
boost::fibers::fiber f2( & bar, std::ref( chan) );
f1.join();
f2.join();
std::cout << "done." << std::endl;
return EXIT_SUCCESS;
} catch ( std::exception const& e) {
std::cerr << "exception: " << e.what() << std::endl;
} catch (...) {
std::cerr << "unhandled exception" << std::endl;
}
return EXIT_FAILURE;
}
|