]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | |
2 | // Copyright Oliver Kowalke 2014. | |
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 | ||
10 | #include <boost/config.hpp> | |
11 | ||
12 | #include <boost/coroutine2/all.hpp> | |
13 | ||
14 | #ifdef BOOST_MSVC //MS VisualStudio | |
15 | __declspec(noinline) void access( char *buf); | |
16 | #else // GCC | |
17 | void access( char *buf) __attribute__ ((noinline)); | |
18 | #endif | |
19 | void access( char *buf) | |
20 | { | |
21 | buf[0] = '\0'; | |
22 | } | |
23 | ||
24 | void bar( int i) | |
25 | { | |
26 | char buf[4 * 1024]; | |
27 | ||
28 | if ( i > 0) | |
29 | { | |
30 | access( buf); | |
31 | std::cout << i << ". iteration" << std::endl; | |
32 | bar( i - 1); | |
33 | } | |
34 | } | |
35 | ||
36 | int main() { | |
37 | int count = 384; | |
38 | ||
39 | #if defined(BOOST_USE_SEGMENTED_STACKS) | |
40 | std::cout << "using segmented_stack stacks: allocates " << count << " * 4kB == " << 4 * count << "kB on stack, "; | |
41 | std::cout << "initial stack size = " << boost::context::segmented_stack::traits_type::default_size() / 1024 << "kB" << std::endl; | |
42 | std::cout << "application should not fail" << std::endl; | |
43 | #else | |
44 | std::cout << "using standard stacks: allocates " << count << " * 4kB == " << 4 * count << "kB on stack, "; | |
45 | std::cout << "initial stack size = " << boost::context::fixedsize_stack::traits_type::default_size() / 1024 << "kB" << std::endl; | |
46 | std::cout << "application might fail" << std::endl; | |
47 | #endif | |
48 | ||
49 | boost::coroutines2::coroutine< void >::push_type sink( | |
50 | [&]( boost::coroutines2::coroutine< void >::pull_type & source) { | |
51 | bar( count); | |
52 | source(); | |
53 | }); | |
54 | ||
55 | sink(); | |
56 | ||
57 | std::cout << "main: Done" << std::endl; | |
58 | ||
59 | return 0; | |
60 | } |