mirror of
https://github.com/boostorg/documentation-fixes.git
synced 2026-01-19 04:12:08 +00:00
Update fiber documentation
This commit is contained in:
262
boost_1_63_0/libs/fiber/doc/html/fiber/performance.html
Normal file
262
boost_1_63_0/libs/fiber/doc/html/fiber/performance.html
Normal file
@@ -0,0 +1,262 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Performance</title>
|
||||
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
|
||||
<link rel="home" href="../index.html" title="Chapter 1. Fiber">
|
||||
<link rel="up" href="../index.html" title="Chapter 1. Fiber">
|
||||
<link rel="prev" href="integration/deeper_dive_into___boost_asio__.html" title="Deeper Dive into Boost.Asio">
|
||||
<link rel="next" href="performance/tweaking.html" title="Tweaking">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="integration/deeper_dive_into___boost_asio__.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="performance/tweaking.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="fiber.performance"></a><a class="link" href="performance.html" title="Performance">Performance</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl class="toc"><dt><span class="section"><a href="performance/tweaking.html">Tweaking</a></span></dt></dl></div>
|
||||
<p>
|
||||
Performance measurements were taken using <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">highresolution_clock</span></code>,
|
||||
with overhead corrections. The code was compiled with gcc-6.20, using build
|
||||
options: variant = release, optimization = speed. Tests were executed on Intel
|
||||
Core i7-4770S 3.10GHz, 4 cores with 8 hyperthreads (4C/8T), running Linux (4.7.0/x86_64).
|
||||
</p>
|
||||
<p>
|
||||
Measurements headed 1C/1T were run in a single-threaded process.
|
||||
</p>
|
||||
<p>
|
||||
The <a href="https://github.com/atemerev/skynet" target="_top">microbenchmark <span class="emphasis"><em>syknet</em></span></a>
|
||||
from Alexander Temerev was ported and used for performance measurements. At
|
||||
the root the test spawns 10 threads-of-execution (ToE), e.g. actor/goroutine/fiber
|
||||
etc.. Each spawned ToE spawns additional 10 ToEs ... until 100000 ToEs are
|
||||
created. ToEs return back ther ordinal numbers (0 ... 99999), which are summed
|
||||
on the previous level and sent back upstream, until reaching the root. The
|
||||
test was run 10-20 times, producing a range of values for each measurement.
|
||||
</p>
|
||||
<div class="table">
|
||||
<a name="fiber.performance.time_per_actor_erlang_process_goroutine__other_languages___average_over_100_000_"></a><p class="title"><b>Table 1.1. time per actor/erlang process/goroutine (other languages) (average over
|
||||
100,000)</b></p>
|
||||
<div class="table-contents"><table class="table" summary="time per actor/erlang process/goroutine (other languages) (average over
|
||||
100,000)">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
Haskell | stack-1.0.4
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Erlang | erts-7.0
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Go | go1.6.1 (GOMAXPROCS == default)
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Go | go1.6.1 (GOMAXPROCS == 8)
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody><tr>
|
||||
<td>
|
||||
<p>
|
||||
0.32 µs
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
0.64 µs - 1.21 µs
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.52 µs - 1.64 µs
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
0.70 µs - 0.98 µs
|
||||
</p>
|
||||
</td>
|
||||
</tr></tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
<br class="table-break"><p>
|
||||
<code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">thread</span></code> can not be tested at this time (C++14)
|
||||
because the API does not allow to set thread stack size (idefault on Linux
|
||||
2MB, on Windows 1MB). An out-of-memory error is likely. With pthreads the stack
|
||||
size is set 8kBC.
|
||||
</p>
|
||||
<div class="table">
|
||||
<a name="fiber.performance.time_per_thread__average_over__10_000____unable_to_spawn_100_000_threads_"></a><p class="title"><b>Table 1.2. time per thread (average over *10,000* - unable to spawn 100,000 threads)</b></p>
|
||||
<div class="table-contents"><table class="table" summary="time per thread (average over *10,000* - unable to spawn 100,000 threads)">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
pthread
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">thread</span></code>
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody><tr>
|
||||
<td>
|
||||
<p>
|
||||
14.4 µs - 20.8 µs
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
18.8 µs - 28.1 µs
|
||||
</p>
|
||||
</td>
|
||||
</tr></tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
<br class="table-break"><p>
|
||||
The test utilizes 4 cores with Symmetric MultiThreading enabled (8 logical
|
||||
CPUs). The fiber stacks are allocated by <a class="link" href="stack.html#class_fixedsize_stack"><code class="computeroutput">fixedsize_stack</code></a>.
|
||||
</p>
|
||||
<p>
|
||||
As the benchmark shows, the memory allocation algorithm is significant for
|
||||
performance in a multithreaded environment. The tests use glibc’s memory allocation
|
||||
algorithm (based on ptmalloc2) as well as Google’s <a href="http://goog-perftools.sourceforge.net/doc/tcmalloc.html" target="_top">TCmalloc</a>
|
||||
(via linkflags="-ltcmalloc").<a href="#ftn.fiber.performance.f0" class="footnote" name="fiber.performance.f0"><sup class="footnote">[9]</sup></a>
|
||||
</p>
|
||||
<p>
|
||||
The <a class="link" href="scheduling.html#class_shared_work"><code class="computeroutput">shared_work</code></a> scheduling algorithm uses one global queue,
|
||||
containing fibers ready to run, shared between all threads. The work is distributed
|
||||
equally over all threads. In the <a class="link" href="scheduling.html#class_work_stealing"><code class="computeroutput">work_stealing</code></a> scheduling
|
||||
algorithm, each thread has its own local queue. Fibers that are ready to run
|
||||
are pushed to and popped from the local queue. If the queue runs out of ready
|
||||
fibers, fibers are stolen from the local queues of other participating threads.
|
||||
</p>
|
||||
<div class="table">
|
||||
<a name="fiber.performance.time_per_fiber__average_over_100_000_"></a><p class="title"><b>Table 1.3. time per fiber (average over 100,000)</b></p>
|
||||
<div class="table-contents"><table class="table" summary="time per fiber (average over 100,000)">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
fiber (4C/8T, work stealing, tcmalloc)
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
fiber (4C/8T, work stealing)
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
fiber (4C/8T, work sharing, tcmalloc)
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
fiber (4C/8T, work sharing)
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
fiber (1C/1T, round robin, tcmalloc)
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
fiber (1C/1T, round robin)
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody><tr>
|
||||
<td>
|
||||
<p>
|
||||
0.13 µs - 0.26 µs
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
0.35 µs - 0.66 µs
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
0.62 µs - 0.80 µs
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
0.90 µs - 1.11 µs
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
0.90 µs - 1.03 µs
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
0.91 µs - 1.28 µs
|
||||
</p>
|
||||
</td>
|
||||
</tr></tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
<br class="table-break"><div class="footnotes">
|
||||
<br><hr style="width:100; text-align:left;margin-left: 0">
|
||||
<div id="ftn.fiber.performance.f0" class="footnote"><p><a href="#fiber.performance.f0" class="para"><sup class="para">[9] </sup></a>
|
||||
Tais B. Ferreira, Rivalino Matias, Autran Macedo, Lucio B. Araujo <span class="quote">“<span class="quote">An
|
||||
Experimental Study on Memory Allocators in Multicore and Multithreaded Applications</span>”</span>,
|
||||
PDCAT ’11 Proceedings of the 2011 12th International Conference on Parallel
|
||||
and Distributed Computing, Applications and Technologies, pages 92-98
|
||||
</p></div>
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2013 Oliver Kowalke<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="integration/deeper_dive_into___boost_asio__.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="performance/tweaking.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
632
boost_1_63_0/libs/fiber/doc/html/fiber/stack.html
Normal file
632
boost_1_63_0/libs/fiber/doc/html/fiber/stack.html
Normal file
@@ -0,0 +1,632 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Stack allocation</title>
|
||||
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
|
||||
<link rel="home" href="../index.html" title="Chapter 1. Fiber">
|
||||
<link rel="up" href="../index.html" title="Chapter 1. Fiber">
|
||||
<link rel="prev" href="scheduling.html" title="Scheduling">
|
||||
<link rel="next" href="stack/valgrind.html" title="Support for valgrind">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="scheduling.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="stack/valgrind.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="fiber.stack"></a><a name="stack"></a><a class="link" href="stack.html" title="Stack allocation">Stack allocation</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl class="toc"><dt><span class="section"><a href="stack/valgrind.html">Support for valgrind</a></span></dt></dl></div>
|
||||
<p>
|
||||
A <a class="link" href="fiber_mgmt/fiber.html#class_fiber"><code class="computeroutput">fiber</code></a> uses internally an <a href="http://www.boost.org/doc/libs/release/libs/context/doc/html/context/ecv2.html" target="_top"><span class="emphasis"><em>execution_context</em></span></a>
|
||||
which manages a set of registers and a stack. The memory used by the stack
|
||||
is allocated/deallocated via a <span class="emphasis"><em>stack_allocator</em></span> which is
|
||||
required to model a <a class="link" href="stack.html#stack_allocator_concept"><span class="emphasis"><em>stack-allocator
|
||||
concept</em></span></a>.
|
||||
</p>
|
||||
<p>
|
||||
A <span class="emphasis"><em>stack_allocator</em></span> can be passed to <a class="link" href="fiber_mgmt/fiber.html#fiber_fiber"><code class="computeroutput"><span class="identifier">fiber</span><span class="special">::</span><span class="identifier">fiber</span><span class="special">()</span></code></a> or to <a class="link" href="synchronization/futures/future.html#fibers_async"><code class="computeroutput">fibers::async()</code></a>.
|
||||
</p>
|
||||
<a name="stack_allocator_concept"></a><h4>
|
||||
<a name="fiber.stack.h0"></a>
|
||||
<span class="phrase"><a name="fiber.stack.stack_allocator_concept"></a></span><a class="link" href="stack.html#fiber.stack.stack_allocator_concept">stack-allocator
|
||||
concept</a>
|
||||
</h4>
|
||||
<p>
|
||||
A <span class="emphasis"><em>stack_allocator</em></span> must satisfy the <span class="emphasis"><em>stack-allocator
|
||||
concept</em></span> requirements shown in the following table, in which <code class="computeroutput"><span class="identifier">a</span></code> is an object of a <span class="emphasis"><em>stack_allocator</em></span>
|
||||
type, <code class="computeroutput"><span class="identifier">sctx</span></code> is a <a href="http://www.boost.org/doc/libs/release/libs/context/doc/html/context/stack/stack_context.html" target="_top"><code class="computeroutput"><span class="identifier">stack_context</span></code></a>, and <code class="computeroutput"><span class="identifier">size</span></code> is a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span></code>:
|
||||
</p>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
expression
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
return type
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
notes
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">a</span><span class="special">(</span><span class="identifier">size</span><span class="special">)</span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
creates a stack allocator
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">a</span><span class="special">.</span><span class="identifier">allocate</span><span class="special">()</span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<a href="http://www.boost.org/doc/libs/release/libs/context/doc/html/context/stack/stack_context.html" target="_top"><code class="computeroutput"><span class="identifier">stack_context</span></code></a>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
creates a stack
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">a</span><span class="special">.</span><span class="identifier">deallocate</span><span class="special">(</span>
|
||||
<span class="identifier">sctx</span><span class="special">)</span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="keyword">void</span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
deallocates the stack created by <code class="computeroutput"><span class="identifier">a</span><span class="special">.</span><span class="identifier">allocate</span><span class="special">()</span></code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
<div class="important"><table border="0" summary="Important">
|
||||
<tr>
|
||||
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../../../doc/src/images/important.png"></td>
|
||||
<th align="left">Important</th>
|
||||
</tr>
|
||||
<tr><td align="left" valign="top"><p>
|
||||
The implementation of <code class="computeroutput"><span class="identifier">allocate</span><span class="special">()</span></code> might include logic to protect against
|
||||
exceeding the context's available stack size rather than leaving it as undefined
|
||||
behaviour.
|
||||
</p></td></tr>
|
||||
</table></div>
|
||||
<div class="important"><table border="0" summary="Important">
|
||||
<tr>
|
||||
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../../../doc/src/images/important.png"></td>
|
||||
<th align="left">Important</th>
|
||||
</tr>
|
||||
<tr><td align="left" valign="top"><p>
|
||||
Calling <code class="computeroutput"><span class="identifier">deallocate</span><span class="special">()</span></code>
|
||||
with a <a href="http://www.boost.org/doc/libs/release/libs/context/doc/html/context/stack/stack_context.html" target="_top"><code class="computeroutput"><span class="identifier">stack_context</span></code></a> not obtained from
|
||||
<code class="computeroutput"><span class="identifier">allocate</span><span class="special">()</span></code>
|
||||
results in undefined behaviour.
|
||||
</p></td></tr>
|
||||
</table></div>
|
||||
<div class="note"><table border="0" summary="Note">
|
||||
<tr>
|
||||
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../doc/src/images/note.png"></td>
|
||||
<th align="left">Note</th>
|
||||
</tr>
|
||||
<tr><td align="left" valign="top"><p>
|
||||
The memory for the stack is not required to be aligned; alignment takes place
|
||||
inside <a href="http://www.boost.org/doc/libs/release/libs/context/doc/html/context/ecv2.html" target="_top"><span class="emphasis"><em>execution_context</em></span></a>.
|
||||
</p></td></tr>
|
||||
</table></div>
|
||||
<p>
|
||||
See also <a href="http://www.boost.org/doc/libs/release/libs/context/doc/html/context/stack.html" target="_top">Boost.Context
|
||||
stack allocation</a>. In particular, <code class="computeroutput"><span class="identifier">traits_type</span></code>
|
||||
methods are as described for <a href="http://www.boost.org/doc/libs/release/libs/context/doc/html/context/stack/stack_traits.html" target="_top"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">context</span><span class="special">::</span><span class="identifier">stack_traits</span></code></a>.
|
||||
</p>
|
||||
<p>
|
||||
</p>
|
||||
<h5>
|
||||
<a name="class_protected_fixedsize_stack_bridgehead"></a>
|
||||
<span class="phrase"><a name="class_protected_fixedsize_stack"></a></span>
|
||||
<a class="link" href="stack.html#class_protected_fixedsize_stack">Class
|
||||
<code class="computeroutput">protected_fixedsize_stack</code></a>
|
||||
</h5>
|
||||
<p>
|
||||
</p>
|
||||
<p>
|
||||
<span class="bold"><strong>Boost.Fiber</strong></span> provides the class <a class="link" href="stack.html#class_protected_fixedsize_stack"><code class="computeroutput">protected_fixedsize_stack</code></a> which
|
||||
models the <a class="link" href="stack.html#stack_allocator_concept"><span class="emphasis"><em>stack-allocator
|
||||
concept</em></span></a>. It appends a guard page at the end of each stack
|
||||
to protect against exceeding the stack. If the guard page is accessed (read
|
||||
or write operation) a segmentation fault/access violation is generated by the
|
||||
operating system.
|
||||
</p>
|
||||
<div class="important"><table border="0" summary="Important">
|
||||
<tr>
|
||||
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../../../doc/src/images/important.png"></td>
|
||||
<th align="left">Important</th>
|
||||
</tr>
|
||||
<tr><td align="left" valign="top"><p>
|
||||
Using <a class="link" href="stack.html#class_protected_fixedsize_stack"><code class="computeroutput">protected_fixedsize_stack</code></a> is expensive.
|
||||
Launching a new fiber with a stack of this type incurs the overhead of setting
|
||||
the memory protection; once allocated, this stack is just as efficient to
|
||||
use as <a class="link" href="stack.html#class_fixedsize_stack"><code class="computeroutput">fixedsize_stack</code></a>.
|
||||
</p></td></tr>
|
||||
</table></div>
|
||||
<div class="note"><table border="0" summary="Note">
|
||||
<tr>
|
||||
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../doc/src/images/note.png"></td>
|
||||
<th align="left">Note</th>
|
||||
</tr>
|
||||
<tr><td align="left" valign="top"><p>
|
||||
The appended <code class="computeroutput"><span class="identifier">guard</span> <span class="identifier">page</span></code>
|
||||
is <span class="bold"><strong>not</strong></span> mapped to physical memory, only virtual
|
||||
addresses are used.
|
||||
</p></td></tr>
|
||||
</table></div>
|
||||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">fiber</span><span class="special">/</span><span class="identifier">protected_fixedsize</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span>
|
||||
<span class="keyword">namespace</span> <span class="identifier">fibers</span> <span class="special">{</span>
|
||||
|
||||
<span class="keyword">struct</span> <span class="identifier">protected_fixedsize</span> <span class="special">{</span>
|
||||
<span class="identifier">protected_fixesize</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">size</span> <span class="special">=</span> <span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">default_size</span><span class="special">());</span>
|
||||
|
||||
<span class="identifier">stack_context</span> <span class="identifier">allocate</span><span class="special">();</span>
|
||||
|
||||
<span class="keyword">void</span> <span class="identifier">deallocate</span><span class="special">(</span> <span class="identifier">stack_context</span> <span class="special">&);</span>
|
||||
<span class="special">}</span>
|
||||
|
||||
<span class="special">}}</span>
|
||||
</pre>
|
||||
<p>
|
||||
</p>
|
||||
<h5>
|
||||
<a name="protected_fixedsize_allocate_bridgehead"></a>
|
||||
<span class="phrase"><a name="protected_fixedsize_allocate"></a></span>
|
||||
<a class="link" href="stack.html#protected_fixedsize_allocate">Member
|
||||
function <code class="computeroutput">allocate</code>()</a>
|
||||
</h5>
|
||||
<p>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">stack_context</span> <span class="identifier">allocate</span><span class="special">();</span>
|
||||
</pre>
|
||||
<div class="variablelist">
|
||||
<p class="title"><b></b></p>
|
||||
<dl class="variablelist">
|
||||
<dt><span class="term">Preconditions:</span></dt>
|
||||
<dd><p>
|
||||
<code class="computeroutput"><span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">minimum_size</span><span class="special">()</span>
|
||||
<span class="special"><=</span> <span class="identifier">size</span></code>
|
||||
and <code class="computeroutput"><span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">is_unbounded</span><span class="special">()</span>
|
||||
<span class="special">||</span> <span class="special">(</span>
|
||||
<span class="identifier">size</span> <span class="special"><=</span>
|
||||
<span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">maximum_size</span><span class="special">()</span>
|
||||
<span class="special">)</span></code>.
|
||||
</p></dd>
|
||||
<dt><span class="term">Effects:</span></dt>
|
||||
<dd><p>
|
||||
Allocates memory of at least <code class="computeroutput"><span class="identifier">size</span></code>
|
||||
bytes and stores a pointer to the stack and its actual size in <code class="computeroutput"><span class="identifier">sctx</span></code>. Depending on the architecture
|
||||
(the stack grows downwards/upwards) the stored address is the highest/lowest
|
||||
address of the stack.
|
||||
</p></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<p>
|
||||
</p>
|
||||
<h5>
|
||||
<a name="protected_fixesize_deallocate_bridgehead"></a>
|
||||
<span class="phrase"><a name="protected_fixesize_deallocate"></a></span>
|
||||
<a class="link" href="stack.html#protected_fixesize_deallocate">Member
|
||||
function <code class="computeroutput">deallocate</code>()</a>
|
||||
</h5>
|
||||
<p>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">deallocate</span><span class="special">(</span> <span class="identifier">stack_context</span> <span class="special">&</span> <span class="identifier">sctx</span><span class="special">);</span>
|
||||
</pre>
|
||||
<div class="variablelist">
|
||||
<p class="title"><b></b></p>
|
||||
<dl class="variablelist">
|
||||
<dt><span class="term">Preconditions:</span></dt>
|
||||
<dd><p>
|
||||
<code class="computeroutput"><span class="identifier">sctx</span><span class="special">.</span><span class="identifier">sp</span></code> is valid, <code class="computeroutput"><span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">minimum_size</span><span class="special">()</span> <span class="special"><=</span> <span class="identifier">sctx</span><span class="special">.</span><span class="identifier">size</span></code> and <code class="computeroutput"><span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">is_unbounded</span><span class="special">()</span> <span class="special">||</span> <span class="special">(</span> <span class="identifier">sctx</span><span class="special">.</span><span class="identifier">size</span> <span class="special"><=</span> <span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">maximum_size</span><span class="special">()</span> <span class="special">)</span></code>.
|
||||
</p></dd>
|
||||
<dt><span class="term">Effects:</span></dt>
|
||||
<dd><p>
|
||||
Deallocates the stack space.
|
||||
</p></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<p>
|
||||
</p>
|
||||
<h5>
|
||||
<a name="class_pooled_fixedsize_stack_bridgehead"></a>
|
||||
<span class="phrase"><a name="class_pooled_fixedsize_stack"></a></span>
|
||||
<a class="link" href="stack.html#class_pooled_fixedsize_stack">Class
|
||||
<code class="computeroutput">pooled_fixedsize_stack</code></a>
|
||||
</h5>
|
||||
<p>
|
||||
</p>
|
||||
<p>
|
||||
<span class="bold"><strong>Boost.Fiber</strong></span> provides the class <a class="link" href="stack.html#class_pooled_fixedsize_stack"><code class="computeroutput">pooled_fixedsize_stack</code></a> which
|
||||
models the <a class="link" href="stack.html#stack_allocator_concept"><span class="emphasis"><em>stack-allocator
|
||||
concept</em></span></a>. In contrast to <a class="link" href="stack.html#class_protected_fixedsize_stack"><code class="computeroutput">protected_fixedsize_stack</code></a> it
|
||||
does not append a guard page at the end of each stack. The memory is managed
|
||||
internally by <a href="http://www.boost.org/doc/libs/release/libs/pool/doc/html/boost/pool.html" target="_top"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">pool</span><span class="special"><></span></code></a>.
|
||||
</p>
|
||||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">fiber</span><span class="special">/</span><span class="identifier">pooled_fixedsize_stack</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span>
|
||||
<span class="keyword">namespace</span> <span class="identifier">fibers</span> <span class="special">{</span>
|
||||
|
||||
<span class="keyword">struct</span> <span class="identifier">pooled_fixedsize_stack</span> <span class="special">{</span>
|
||||
<span class="identifier">pooled_fixedsize_stack</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">stack_size</span> <span class="special">=</span> <span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">default_size</span><span class="special">(),</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">next_size</span> <span class="special">=</span> <span class="number">32</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">max_size</span> <span class="special">=</span> <span class="number">0</span><span class="special">);</span>
|
||||
|
||||
<span class="identifier">stack_context</span> <span class="identifier">allocate</span><span class="special">();</span>
|
||||
|
||||
<span class="keyword">void</span> <span class="identifier">deallocate</span><span class="special">(</span> <span class="identifier">stack_context</span> <span class="special">&);</span>
|
||||
<span class="special">}</span>
|
||||
|
||||
<span class="special">}}</span>
|
||||
</pre>
|
||||
<p>
|
||||
</p>
|
||||
<h5>
|
||||
<a name="pooled_fixedsize_bridgehead"></a>
|
||||
<span class="phrase"><a name="pooled_fixedsize"></a></span>
|
||||
<a class="link" href="stack.html#pooled_fixedsize">Constructor</a>
|
||||
</h5>
|
||||
<p>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">pooled_fixedsize_stack</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">stack_size</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">next_size</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">max_size</span><span class="special">);</span>
|
||||
</pre>
|
||||
<div class="variablelist">
|
||||
<p class="title"><b></b></p>
|
||||
<dl class="variablelist">
|
||||
<dt><span class="term">Preconditions:</span></dt>
|
||||
<dd><p>
|
||||
<code class="computeroutput"><span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">is_unbounded</span><span class="special">()</span>
|
||||
<span class="special">||</span> <span class="special">(</span>
|
||||
<span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">maximum_size</span><span class="special">()</span>
|
||||
<span class="special">>=</span> <span class="identifier">stack_size</span><span class="special">)</span></code> and <code class="computeroutput"><span class="number">0</span>
|
||||
<span class="special"><</span> <span class="identifier">next_size</span></code>.
|
||||
</p></dd>
|
||||
<dt><span class="term">Effects:</span></dt>
|
||||
<dd><p>
|
||||
Allocates memory of at least <code class="computeroutput"><span class="identifier">stack_size</span></code>
|
||||
bytes and stores a pointer to the stack and its actual size in <code class="computeroutput"><span class="identifier">sctx</span></code>. Depending on the architecture
|
||||
(the stack grows downwards/upwards) the stored address is the highest/lowest
|
||||
address of the stack. Argument <code class="computeroutput"><span class="identifier">next_size</span></code>
|
||||
determines the number of stacks to request from the system the first
|
||||
time that <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||||
needs to allocate system memory. The third argument <code class="computeroutput"><span class="identifier">max_size</span></code>
|
||||
controls how much memory might be allocated for stacks — a value of zero
|
||||
means no upper limit.
|
||||
</p></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<p>
|
||||
</p>
|
||||
<h5>
|
||||
<a name="pooled_fixedsize_allocate_bridgehead"></a>
|
||||
<span class="phrase"><a name="pooled_fixedsize_allocate"></a></span>
|
||||
<a class="link" href="stack.html#pooled_fixedsize_allocate">Member
|
||||
function <code class="computeroutput">allocate</code>()</a>
|
||||
</h5>
|
||||
<p>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">stack_context</span> <span class="identifier">allocate</span><span class="special">();</span>
|
||||
</pre>
|
||||
<div class="variablelist">
|
||||
<p class="title"><b></b></p>
|
||||
<dl class="variablelist">
|
||||
<dt><span class="term">Preconditions:</span></dt>
|
||||
<dd><p>
|
||||
<code class="computeroutput"><span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">is_unbounded</span><span class="special">()</span>
|
||||
<span class="special">||</span> <span class="special">(</span>
|
||||
<span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">maximum_size</span><span class="special">()</span>
|
||||
<span class="special">>=</span> <span class="identifier">stack_size</span><span class="special">)</span></code>.
|
||||
</p></dd>
|
||||
<dt><span class="term">Effects:</span></dt>
|
||||
<dd><p>
|
||||
Allocates memory of at least <code class="computeroutput"><span class="identifier">stack_size</span></code>
|
||||
bytes and stores a pointer to the stack and its actual size in <code class="computeroutput"><span class="identifier">sctx</span></code>. Depending on the architecture
|
||||
(the stack grows downwards/upwards) the stored address is the highest/lowest
|
||||
address of the stack.
|
||||
</p></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<p>
|
||||
</p>
|
||||
<h5>
|
||||
<a name="pooled_fixesize_deallocate_bridgehead"></a>
|
||||
<span class="phrase"><a name="pooled_fixesize_deallocate"></a></span>
|
||||
<a class="link" href="stack.html#pooled_fixesize_deallocate">Member
|
||||
function <code class="computeroutput">deallocate</code>()</a>
|
||||
</h5>
|
||||
<p>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">deallocate</span><span class="special">(</span> <span class="identifier">stack_context</span> <span class="special">&</span> <span class="identifier">sctx</span><span class="special">);</span>
|
||||
</pre>
|
||||
<div class="variablelist">
|
||||
<p class="title"><b></b></p>
|
||||
<dl class="variablelist">
|
||||
<dt><span class="term">Preconditions:</span></dt>
|
||||
<dd><p>
|
||||
<code class="computeroutput"><span class="identifier">sctx</span><span class="special">.</span><span class="identifier">sp</span></code> is valid, <code class="computeroutput"><span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">is_unbounded</span><span class="special">()</span> <span class="special">||</span> <span class="special">(</span> <span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">maximum_size</span><span class="special">()</span> <span class="special">>=</span> <span class="identifier">sctx</span><span class="special">.</span><span class="identifier">size</span><span class="special">)</span></code>.
|
||||
</p></dd>
|
||||
<dt><span class="term">Effects:</span></dt>
|
||||
<dd><p>
|
||||
Deallocates the stack space.
|
||||
</p></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="note"><table border="0" summary="Note">
|
||||
<tr>
|
||||
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../doc/src/images/note.png"></td>
|
||||
<th align="left">Note</th>
|
||||
</tr>
|
||||
<tr><td align="left" valign="top"><p>
|
||||
This stack allocator is not thread safe.
|
||||
</p></td></tr>
|
||||
</table></div>
|
||||
<p>
|
||||
</p>
|
||||
<h5>
|
||||
<a name="class_fixedsize_stack_bridgehead"></a>
|
||||
<span class="phrase"><a name="class_fixedsize_stack"></a></span>
|
||||
<a class="link" href="stack.html#class_fixedsize_stack">Class
|
||||
<code class="computeroutput">fixedsize_stack</code></a>
|
||||
</h5>
|
||||
<p>
|
||||
</p>
|
||||
<p>
|
||||
<span class="bold"><strong>Boost.Fiber</strong></span> provides the class <a class="link" href="stack.html#class_fixedsize_stack"><code class="computeroutput">fixedsize_stack</code></a> which
|
||||
models the <a class="link" href="stack.html#stack_allocator_concept"><span class="emphasis"><em>stack-allocator
|
||||
concept</em></span></a>. In contrast to <a class="link" href="stack.html#class_protected_fixedsize_stack"><code class="computeroutput">protected_fixedsize_stack</code></a> it
|
||||
does not append a guard page at the end of each stack. The memory is simply
|
||||
managed by <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">malloc</span><span class="special">()</span></code>
|
||||
and <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">free</span><span class="special">()</span></code>.
|
||||
</p>
|
||||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">context</span><span class="special">/</span><span class="identifier">fixedsize_stack</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span>
|
||||
<span class="keyword">namespace</span> <span class="identifier">fibers</span> <span class="special">{</span>
|
||||
|
||||
<span class="keyword">struct</span> <span class="identifier">fixedsize_stack</span> <span class="special">{</span>
|
||||
<span class="identifier">fixedsize_stack</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">size</span> <span class="special">=</span> <span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">default_size</span><span class="special">());</span>
|
||||
|
||||
<span class="identifier">stack_context</span> <span class="identifier">allocate</span><span class="special">();</span>
|
||||
|
||||
<span class="keyword">void</span> <span class="identifier">deallocate</span><span class="special">(</span> <span class="identifier">stack_context</span> <span class="special">&);</span>
|
||||
<span class="special">}</span>
|
||||
|
||||
<span class="special">}}</span>
|
||||
</pre>
|
||||
<p>
|
||||
</p>
|
||||
<h5>
|
||||
<a name="fixedsize_allocate_bridgehead"></a>
|
||||
<span class="phrase"><a name="fixedsize_allocate"></a></span>
|
||||
<a class="link" href="stack.html#fixedsize_allocate">Member function
|
||||
<code class="computeroutput">allocate</code>()</a>
|
||||
</h5>
|
||||
<p>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">stack_context</span> <span class="identifier">allocate</span><span class="special">();</span>
|
||||
</pre>
|
||||
<div class="variablelist">
|
||||
<p class="title"><b></b></p>
|
||||
<dl class="variablelist">
|
||||
<dt><span class="term">Preconditions:</span></dt>
|
||||
<dd><p>
|
||||
<code class="computeroutput"><span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">minimum_size</span><span class="special">()</span>
|
||||
<span class="special"><=</span> <span class="identifier">size</span></code>
|
||||
and <code class="computeroutput"><span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">is_unbounded</span><span class="special">()</span>
|
||||
<span class="special">||</span> <span class="special">(</span>
|
||||
<span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">maximum_size</span><span class="special">()</span>
|
||||
<span class="special">>=</span> <span class="identifier">size</span><span class="special">)</span></code>.
|
||||
</p></dd>
|
||||
<dt><span class="term">Effects:</span></dt>
|
||||
<dd><p>
|
||||
Allocates memory of at least <code class="computeroutput"><span class="identifier">size</span></code>
|
||||
bytes and stores a pointer to the stack and its actual size in <code class="computeroutput"><span class="identifier">sctx</span></code>. Depending on the architecture
|
||||
(the stack grows downwards/upwards) the stored address is the highest/lowest
|
||||
address of the stack.
|
||||
</p></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<p>
|
||||
</p>
|
||||
<h5>
|
||||
<a name="fixesize_deallocate_bridgehead"></a>
|
||||
<span class="phrase"><a name="fixesize_deallocate"></a></span>
|
||||
<a class="link" href="stack.html#fixesize_deallocate">Member
|
||||
function <code class="computeroutput">deallocate</code>()</a>
|
||||
</h5>
|
||||
<p>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">deallocate</span><span class="special">(</span> <span class="identifier">stack_context</span> <span class="special">&</span> <span class="identifier">sctx</span><span class="special">);</span>
|
||||
</pre>
|
||||
<div class="variablelist">
|
||||
<p class="title"><b></b></p>
|
||||
<dl class="variablelist">
|
||||
<dt><span class="term">Preconditions:</span></dt>
|
||||
<dd><p>
|
||||
<code class="computeroutput"><span class="identifier">sctx</span><span class="special">.</span><span class="identifier">sp</span></code> is valid, <code class="computeroutput"><span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">minimum_size</span><span class="special">()</span> <span class="special"><=</span> <span class="identifier">sctx</span><span class="special">.</span><span class="identifier">size</span></code> and <code class="computeroutput"><span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">is_unbounded</span><span class="special">()</span> <span class="special">||</span> <span class="special">(</span> <span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">maximum_size</span><span class="special">()</span> <span class="special">>=</span> <span class="identifier">sctx</span><span class="special">.</span><span class="identifier">size</span><span class="special">)</span></code>.
|
||||
</p></dd>
|
||||
<dt><span class="term">Effects:</span></dt>
|
||||
<dd><p>
|
||||
Deallocates the stack space.
|
||||
</p></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<p>
|
||||
</p>
|
||||
<h5>
|
||||
<a name="class_segmented_stack_bridgehead"></a>
|
||||
<span class="phrase"><a name="class_segmented_stack"></a></span>
|
||||
<a class="link" href="stack.html#class_segmented_stack">Class
|
||||
<code class="computeroutput">segmented_stack</code></a>
|
||||
</h5>
|
||||
<p>
|
||||
</p>
|
||||
<p>
|
||||
<span class="bold"><strong>Boost.Fiber</strong></span> supports usage of a <a class="link" href="stack.html#class_segmented_stack"><code class="computeroutput">segmented_stack</code></a>,
|
||||
i.e. the stack grows on demand. The fiber is created with a minimal stack size
|
||||
which will be increased as required. Class <a class="link" href="stack.html#class_segmented_stack"><code class="computeroutput">segmented_stack</code></a> models
|
||||
the <a class="link" href="stack.html#stack_allocator_concept"><span class="emphasis"><em>stack-allocator concept</em></span></a>.
|
||||
In contrast to <a class="link" href="stack.html#class_protected_fixedsize_stack"><code class="computeroutput">protected_fixedsize_stack</code></a> and
|
||||
<a class="link" href="stack.html#class_fixedsize_stack"><code class="computeroutput">fixedsize_stack</code></a> it creates a stack which grows on demand.
|
||||
</p>
|
||||
<div class="note"><table border="0" summary="Note">
|
||||
<tr>
|
||||
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../doc/src/images/note.png"></td>
|
||||
<th align="left">Note</th>
|
||||
</tr>
|
||||
<tr><td align="left" valign="top"><p>
|
||||
Segmented stacks are currently only supported by <span class="bold"><strong>gcc</strong></span>
|
||||
from version <span class="bold"><strong>4.7</strong></span> and <span class="bold"><strong>clang</strong></span>
|
||||
from version <span class="bold"><strong>3.4</strong></span> onwards. In order to use
|
||||
a <a class="link" href="stack.html#class_segmented_stack"><code class="computeroutput">segmented_stack</code></a> <span class="bold"><strong>Boost.Fiber</strong></span>
|
||||
must be built with property <code class="computeroutput"><span class="identifier">segmented</span><span class="special">-</span><span class="identifier">stacks</span></code>,
|
||||
e.g. <span class="bold"><strong>toolset=gcc segmented-stacks=on</strong></span> at
|
||||
b2/bjam command line.
|
||||
</p></td></tr>
|
||||
</table></div>
|
||||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">fiber</span><span class="special">/</span><span class="identifier">segmented_stack</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span>
|
||||
<span class="keyword">namespace</span> <span class="identifier">fibers</span> <span class="special">{</span>
|
||||
|
||||
<span class="keyword">struct</span> <span class="identifier">segmented_stack</span> <span class="special">{</span>
|
||||
<span class="identifier">segmented_stack</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">stack_size</span> <span class="special">=</span> <span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">default_size</span><span class="special">());</span>
|
||||
|
||||
<span class="identifier">stack_context</span> <span class="identifier">allocate</span><span class="special">();</span>
|
||||
|
||||
<span class="keyword">void</span> <span class="identifier">deallocate</span><span class="special">(</span> <span class="identifier">stack_context</span> <span class="special">&);</span>
|
||||
<span class="special">}</span>
|
||||
|
||||
<span class="special">}}</span>
|
||||
</pre>
|
||||
<p>
|
||||
</p>
|
||||
<h5>
|
||||
<a name="segmented_allocate_bridgehead"></a>
|
||||
<span class="phrase"><a name="segmented_allocate"></a></span>
|
||||
<a class="link" href="stack.html#segmented_allocate">Member function
|
||||
<code class="computeroutput">allocate</code>()</a>
|
||||
</h5>
|
||||
<p>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">stack_context</span> <span class="identifier">allocate</span><span class="special">();</span>
|
||||
</pre>
|
||||
<div class="variablelist">
|
||||
<p class="title"><b></b></p>
|
||||
<dl class="variablelist">
|
||||
<dt><span class="term">Preconditions:</span></dt>
|
||||
<dd><p>
|
||||
<code class="computeroutput"><span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">minimum_size</span><span class="special">()</span>
|
||||
<span class="special"><=</span> <span class="identifier">size</span></code>
|
||||
and <code class="computeroutput"><span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">is_unbounded</span><span class="special">()</span>
|
||||
<span class="special">||</span> <span class="special">(</span>
|
||||
<span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">maximum_size</span><span class="special">()</span>
|
||||
<span class="special">>=</span> <span class="identifier">size</span><span class="special">)</span></code>.
|
||||
</p></dd>
|
||||
<dt><span class="term">Effects:</span></dt>
|
||||
<dd><p>
|
||||
Allocates memory of at least <code class="computeroutput"><span class="identifier">size</span></code>
|
||||
bytes and stores a pointer to the stack and its actual size in <code class="computeroutput"><span class="identifier">sctx</span></code>. Depending on the architecture
|
||||
(the stack grows downwards/upwards) the stored address is the highest/lowest
|
||||
address of the stack.
|
||||
</p></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<p>
|
||||
</p>
|
||||
<h5>
|
||||
<a name="segmented_deallocate_bridgehead"></a>
|
||||
<span class="phrase"><a name="segmented_deallocate"></a></span>
|
||||
<a class="link" href="stack.html#segmented_deallocate">Member
|
||||
function <code class="computeroutput">deallocate</code>()</a>
|
||||
</h5>
|
||||
<p>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">deallocate</span><span class="special">(</span> <span class="identifier">stack_context</span> <span class="special">&</span> <span class="identifier">sctx</span><span class="special">);</span>
|
||||
</pre>
|
||||
<div class="variablelist">
|
||||
<p class="title"><b></b></p>
|
||||
<dl class="variablelist">
|
||||
<dt><span class="term">Preconditions:</span></dt>
|
||||
<dd><p>
|
||||
<code class="computeroutput"><span class="identifier">sctx</span><span class="special">.</span><span class="identifier">sp</span></code> is valid, <code class="computeroutput"><span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">minimum_size</span><span class="special">()</span> <span class="special"><=</span> <span class="identifier">sctx</span><span class="special">.</span><span class="identifier">size</span></code> and <code class="computeroutput"><span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">is_unbounded</span><span class="special">()</span> <span class="special">||</span> <span class="special">(</span> <span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">maximum_size</span><span class="special">()</span> <span class="special">>=</span> <span class="identifier">sctx</span><span class="special">.</span><span class="identifier">size</span><span class="special">)</span></code>.
|
||||
</p></dd>
|
||||
<dt><span class="term">Effects:</span></dt>
|
||||
<dd><p>
|
||||
Deallocates the stack space.
|
||||
</p></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="note"><table border="0" summary="Note">
|
||||
<tr>
|
||||
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../doc/src/images/note.png"></td>
|
||||
<th align="left">Note</th>
|
||||
</tr>
|
||||
<tr><td align="left" valign="top"><p>
|
||||
If the library is compiled for segmented stacks, <a class="link" href="stack.html#class_segmented_stack"><code class="computeroutput">segmented_stack</code></a> is
|
||||
the only available stack allocator.
|
||||
</p></td></tr>
|
||||
</table></div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2013 Oliver Kowalke<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="scheduling.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="stack/valgrind.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
48
boost_1_63_0/libs/fiber/doc/html/fiber/stack/valgrind.html
Normal file
48
boost_1_63_0/libs/fiber/doc/html/fiber/stack/valgrind.html
Normal file
@@ -0,0 +1,48 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Support for valgrind</title>
|
||||
<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
|
||||
<link rel="home" href="../../index.html" title="Chapter 1. Fiber">
|
||||
<link rel="up" href="../stack.html" title="Stack allocation">
|
||||
<link rel="prev" href="../stack.html" title="Stack allocation">
|
||||
<link rel="next" href="../synchronization.html" title="Synchronization">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../stack.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../stack.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../synchronization.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="fiber.stack.valgrind"></a><a class="link" href="valgrind.html" title="Support for valgrind">Support for valgrind</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
Running programs that switch stacks under valgrind causes problems. Property
|
||||
(b2 command-line) <code class="computeroutput"><span class="identifier">valgrind</span><span class="special">=</span><span class="identifier">on</span></code> let
|
||||
valgrind treat the memory regions as stack space which suppresses the errors.
|
||||
</p>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2013 Oliver Kowalke<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../stack.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../stack.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../synchronization.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user