]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/context/example/callcc/segmented.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / context / example / callcc / 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>
9#include <memory>
10
92f5a8d4 11#include <boost/context/continuation.hpp>
7c673cae 12
b32b8144
FG
13namespace ctx = boost::context;
14
7c673cae
FG
15#ifdef BOOST_MSVC //MS VisualStudio
16__declspec(noinline) void access( char *buf);
17#else // GCC
18void access( char *buf) __attribute__ ((noinline));
19#endif
20void access( char *buf) {
21 buf[0] = '\0';
22}
23
24void bar( int i) {
25 char buf[4 * 1024];
26 if ( i > 0) {
27 access( buf);
28 std::cout << i << ". iteration" << std::endl;
29 bar( i - 1);
30 }
31}
32
33int main() {
b32b8144 34 int count = 100*1024;
7c673cae
FG
35#if defined(BOOST_USE_SEGMENTED_STACKS)
36 std::cout << "using segmented_stack stacks: allocates " << count << " * 4kB == " << 4 * count << "kB on stack, ";
11fdf7f2 37 std::cout << "initial stack size = " << ctx::segmented_stack::traits_type::default_size() / 1024 << "kB" << std::endl;
7c673cae
FG
38 std::cout << "application should not fail" << std::endl;
39#else
40 std::cout << "using standard stacks: allocates " << count << " * 4kB == " << 4 * count << "kB on stack, ";
11fdf7f2 41 std::cout << "initial stack size = " << ctx::fixedsize_stack::traits_type::default_size() / 1024 << "kB" << std::endl;
7c673cae
FG
42 std::cout << "application might fail" << std::endl;
43#endif
b32b8144
FG
44 ctx::continuation c = ctx::callcc(
45 [count](ctx::continuation && c){
7c673cae 46 bar( count);
b32b8144 47 return std::move( c);
7c673cae 48 });
7c673cae
FG
49 std::cout << "main: done" << std::endl;
50 return EXIT_SUCCESS;
51}