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

source code of boost/libs/coroutine/example/asymmetric/segmented_stack.cpp