]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/coroutine/example/symmetric/segmented_stack.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / coroutine / example / symmetric / segmented_stack.cpp
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 <iostream>
8
9 #include <boost/assert.hpp>
10 #include <boost/config.hpp>
11 #include <boost/coroutine/all.hpp>
12 #include <boost/thread.hpp>
13
14 int count = 384;
15
16 #ifdef BOOST_MSVC //MS VisualStudio
17 __declspec(noinline) void access( char *buf);
18 #else // GCC
19 void access( char *buf) __attribute__ ((noinline));
20 #endif
21 void access( char *buf)
22 {
23 buf[0] = '\0';
24 }
25
26 void 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 - 1);
35 }
36 }
37
38 void foo( boost::coroutines::symmetric_coroutine< void >::yield_type &)
39 {
40 bar( count);
41 }
42
43 void thread_fn()
44 {
45 {
46 boost::coroutines::symmetric_coroutine< void >::call_type coro( foo);
47 coro();
48 }
49 }
50
51 int main( int argc, char * argv[])
52 {
53 #if defined(BOOST_USE_SEGMENTED_STACKS)
54 std::cout << "using segmented stacks: allocates " << count << " * 4kB == " << 4 * count << "kB on stack, ";
55 std::cout << "initial stack size = " << boost::coroutines::stack_allocator::traits_type::default_size() / 1024 << "kB" << std::endl;
56 std::cout << "application should not fail" << std::endl;
57 #else
58 std::cout << "using standard stacks: allocates " << count << " * 4kB == " << 4 * count << "kB on stack, ";
59 std::cout << "initial stack size = " << boost::coroutines::stack_allocator::traits_type::default_size() / 1024 << "kB" << std::endl;
60 std::cout << "application might fail" << std::endl;
61 #endif
62
63 boost::thread( thread_fn).join();
64
65 return 0;
66 }