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