]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/coroutine2/example/segmented.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / coroutine2 / example / segmented.cpp
CommitLineData
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>
b32b8144 9#include <memory>
7c673cae
FG
10
11#include <boost/coroutine2/all.hpp>
12
13#ifdef BOOST_MSVC //MS VisualStudio
14__declspec(noinline) void access( char *buf);
15#else // GCC
16void access( char *buf) __attribute__ ((noinline));
17#endif
b32b8144 18void access( char *buf) {
7c673cae
FG
19 buf[0] = '\0';
20}
21
b32b8144 22void bar( int i) {
7c673cae 23 char buf[4 * 1024];
b32b8144 24 if ( i > 0) {
7c673cae
FG
25 access( buf);
26 std::cout << i << ". iteration" << std::endl;
27 bar( i - 1);
28 }
29}
30
31int main() {
32 int count = 384;
7c673cae
FG
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
b32b8144
FG
42 boost::coroutines2::coroutine< void >::pull_type coro{
43 [count](boost::coroutines2::coroutine< void >::push_type & coro){
7c673cae 44 bar( count);
b32b8144
FG
45 }};
46 std::cout << "main: done" << std::endl;
47 return EXIT_SUCCESS;
7c673cae 48}