]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/context/example/fiber/segmented.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / context / example / fiber / segmented.cpp
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/context/fiber.hpp>
12
13 namespace ctx = boost::context;
14
15 #ifdef BOOST_MSVC //MS VisualStudio
16 __declspec(noinline) void access( char *buf);
17 #else // GCC
18 void access( char *buf) __attribute__ ((noinline));
19 #endif
20 void access( char *buf) {
21 buf[0] = '\0';
22 }
23
24 void 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
33 int main() {
34 int count = 100*1024;
35 #if defined(BOOST_USE_SEGMENTED_STACKS)
36 std::cout << "using segmented_stack stacks: allocates " << count << " * 4kB == " << 4 * count << "kB on stack, ";
37 std::cout << "initial stack size = " << ctx::segmented_stack::traits_type::default_size() / 1024 << "kB" << std::endl;
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, ";
41 std::cout << "initial stack size = " << ctx::fixedsize_stack::traits_type::default_size() / 1024 << "kB" << std::endl;
42 std::cout << "application might fail" << std::endl;
43 #endif
44 ctx::fiber{
45 [count](ctx::fiber && f){
46 bar( count);
47 return std::move( f);
48 }}.resume();
49 std::cout << "main: done" << std::endl;
50 return EXIT_SUCCESS;
51 }