Imported Upstream version 1.63.0
[platform/upstream/boost.git] / libs / context / doc / context.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN" "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
3 <library id="context" name="Context" dirname="context" last-revision="$Date: 2016/11/27 06:34:58 $"
4  xmlns:xi="http://www.w3.org/2001/XInclude">
5   <libraryinfo>
6     <authorgroup>
7     <author>
8       <firstname>Oliver</firstname> <surname>Kowalke</surname>
9     </author>
10     </authorgroup>
11     <copyright>
12       <year>2014</year> <holder>Oliver Kowalke</holder>
13     </copyright>
14     <legalnotice id="context.legal">
15       <para>
16         Distributed under the Boost Software License, Version 1.0. (See accompanying
17         file LICENSE_1_0.txt or copy at <ulink url="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</ulink>)
18       </para>
19     </legalnotice>
20     <librarypurpose>
21       C++ Library for swiching different user ctx
22     </librarypurpose>
23     <librarycategory name="category:text"></librarycategory>
24   </libraryinfo>
25   <title>Context</title>
26   <section id="context.overview">
27     <title><link linkend="context.overview">Overview</link></title>
28     <para>
29       <emphasis role="bold">Boost.Context</emphasis> is a foundational library that
30       provides a sort of cooperative multitasking on a single thread. By providing
31       an abstraction of the current execution state in the current thread, including
32       the stack (with local variables) and stack pointer, all registers and CPU flags,
33       and the instruction pointer, a <emphasis>execution_context</emphasis> represents
34       a specific point in the application's execution path. This is useful for building
35       higher-level abstractions, like <emphasis>coroutines</emphasis>, <emphasis>cooperative
36       threads (userland threads)</emphasis> or an equivalent to <ulink url="http://msdn.microsoft.com/en-us/library/9k7k7cf0%28v=vs.80%29.aspx">C#
37       keyword <emphasis>yield</emphasis></ulink> in C++.
38     </para>
39     <para>
40       <emphasis>execution_context</emphasis> provides the means to suspend the current
41       execution path and to transfer execution control, thereby permitting another
42       context to run on the current thread. This state full transfer mechanism enables
43       a context to suspend execution from within nested functions and, later, to
44       resume from where it was suspended. While the execution path represented by
45       a <emphasis>execution_context</emphasis> only runs on a single thread, it can
46       be migrated to another thread at any given time.
47     </para>
48     <para>
49       A context switch between threads requires system calls (involving the OS kernel),
50       which can cost more than thousand CPU cycles on x86 CPUs. By contrast, transferring
51       control among them requires only few CPU cycles because it does not involve
52       system calls as it is done within a single thread.
53     </para>
54     <para>
55       In order to use the classes and functions described here, you can either include
56       the specific headers specified by the descriptions of each class or function,
57       or include the master library header:
58     </para>
59 <programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">context</phrase><phrase role="special">/</phrase><phrase role="identifier">all</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
60 </programlisting>
61     <para>
62       which includes all the other headers in turn.
63     </para>
64     <para>
65       All functions and classes are contained in the namespace <emphasis>boost::context</emphasis>.
66     </para>
67     <note>
68       <para>
69         This library requires C++11!
70       </para>
71     </note>
72   </section>
73   <section id="context.requirements">
74     <title><link linkend="context.requirements">Requirements</link></title>
75     <para>
76       <emphasis role="bold">Boost.Context</emphasis> must be built for the particular
77       compiler(s) and CPU architecture(s)s being targeted. <emphasis role="bold">Boost.Context</emphasis>
78       includes assembly code and, therefore, requires GNU as and GNU preprocesspr
79       for supported POSIX systems, MASM for Windows/x86 systems and ARMasm for Windows/arm
80       systems.
81     </para>
82     <note>
83       <para>
84         MASM64 (ml64.exe) is a part of Microsoft's Windows Driver Kit.
85       </para>
86     </note>
87     <important>
88       <para>
89         Please note that <code><phrase role="identifier">address</phrase><phrase
90         role="special">-</phrase><phrase role="identifier">model</phrase><phrase
91         role="special">=</phrase><phrase role="number">64</phrase></code> must be
92         given to bjam command line on 64bit Windows for 64bit build; otherwise 32bit
93         code will be generated.
94       </para>
95     </important>
96     <important>
97       <para>
98         For cross-compiling the lib you must specify certain additional properties
99         at bjam command line: <code><phrase role="identifier">target</phrase><phrase
100         role="special">-</phrase><phrase role="identifier">os</phrase></code>, <code><phrase
101         role="identifier">abi</phrase></code>, <code><phrase role="identifier">binary</phrase><phrase
102         role="special">-</phrase><phrase role="identifier">format</phrase></code>,
103         <code><phrase role="identifier">architecture</phrase></code> and <code><phrase
104         role="identifier">address</phrase><phrase role="special">-</phrase><phrase
105         role="identifier">model</phrase></code>.
106       </para>
107     </important>
108     <important>
109       <para>
110         For safe SEH the property 'asmflags=\safeseh' must be specified at bjam command
111         line.
112       </para>
113     </important>
114   </section>
115   <section id="context.ecv2">
116     <title><anchor id="ecv2"/><link linkend="context.ecv2">Class execution_context
117     (version 2)</link></title>
118     <note>
119       <para>
120         This class is enabled per default.
121       </para>
122     </note>
123     <para>
124       Class <emphasis>execution_context</emphasis> encapsulates context switching
125       and manages the associated context' stack (allocation/deallocation).
126     </para>
127     <para>
128       <emphasis>execution_context</emphasis> allocates the context stack (using its
129       <link linkend="stack"><emphasis>StackAllocator</emphasis></link> argument)
130       and creates a control structure on top of it. This structure is responsible
131       for managing context' stack. The address of the control structure is stored
132       in the first frame of context' stack (e.g. it can not directly accessed from
133       within <emphasis>execution_context</emphasis>). In contrast to <link linkend="ecv1"><emphasis>execution_context</emphasis>
134       (v1)</link> the ownership of the control structure is not shared (no member
135       variable to control structure in <emphasis>execution_context</emphasis>).
136       <emphasis>execution_context</emphasis> keeps internally a state that is moved
137       by a call of <emphasis>execution_context::operator()</emphasis> (<code><phrase
138       role="special">*</phrase><phrase role="keyword">this</phrase></code> will be
139       invalidated), e.g. after a calling <emphasis>execution_context::operator()</emphasis>,
140       <code><phrase role="special">*</phrase><phrase role="keyword">this</phrase></code>
141       can not be used for an additional context switch.
142     </para>
143     <para>
144       <emphasis>execution_context</emphasis> is only move-constructible and move-assignable.
145     </para>
146     <para>
147       The moved state is assigned to a new instance of <emphasis>execution_context</emphasis>.
148       This object becomes the first argument of the context-function, if the context
149       was resumed the first time, or the first element in a tuple returned by <emphasis>execution_context::operator()</emphasis>
150       that has been called in the resumed context. In contrast to <link linkend="ecv1"><emphasis>execution_context</emphasis>
151       (v1)</link>, the context switch is faster because no global pointer etc. is
152       involved.
153     </para>
154     <important>
155       <para>
156         Segmented stacks are not supported by <emphasis>execution_context</emphasis>
157         (v2).
158       </para>
159     </important>
160     <para>
161       On return the context-function of the current context has to specify an <emphasis>execution_context</emphasis>
162       to which the execution control is transferred after termination of the current
163       context.
164     </para>
165     <para>
166       If an instance with valid state goes out of scope and the context-function
167       has not yet returned, the stack is traversed in order to access the control
168       structure (address stored at the first stack frame) and context' stack is deallocated
169       via the <emphasis>StackAllocator</emphasis>. The stack walking makes the destruction
170       of <emphasis>execution_context</emphasis> slow and should be prevented if possible.
171     </para>
172     <para>
173       <emphasis>execution_context</emphasis> expects a <emphasis>context-function</emphasis>
174       with signature <code><phrase role="identifier">execution_context</phrase><phrase
175       role="special">(</phrase><phrase role="identifier">execution_context</phrase>
176       <phrase role="identifier">ctx</phrase><phrase role="special">,</phrase> <phrase
177       role="identifier">Args</phrase> <phrase role="special">...</phrase> <phrase
178       role="identifier">args</phrase><phrase role="special">)</phrase></code>. The
179       parameter <code><phrase role="identifier">ctx</phrase></code> represents the
180       context from which this context was resumed (e.g. that has called <emphasis>execution_context::operator()</emphasis>
181       on <code><phrase role="special">*</phrase><phrase role="keyword">this</phrase></code>)
182       and <code><phrase role="identifier">args</phrase></code> are the data passed
183       to <emphasis>execution_context::operator()</emphasis>. The return value represents
184       the execution_context that has to be resumed, after termiantion of this context.
185     </para>
186     <para>
187       Benefits of <link linkend="ecv2"><emphasis>execution_context</emphasis> (v2)</link>
188       over <link linkend="ecv1"><emphasis>execution_context</emphasis> (v1)</link>
189       are: faster context switch, type-safety of passed/returned arguments.
190     </para>
191     <bridgehead renderas="sect3" id="context.ecv2.h0">
192       <phrase id="context.ecv2.usage_of__emphasis_execution_context__emphasis_"/><link
193       linkend="context.ecv2.usage_of__emphasis_execution_context__emphasis_">usage
194       of <emphasis>execution_context</emphasis></link>
195     </bridgehead>
196 <programlisting><phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">=</phrase><phrase role="number">35</phrase><phrase role="special">;</phrase>
197 <phrase role="identifier">ctx</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">source</phrase><phrase role="special">(</phrase>
198     <phrase role="special">[</phrase><phrase role="identifier">n</phrase><phrase role="special">](</phrase><phrase role="identifier">ctx</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">sink</phrase><phrase role="special">,</phrase><phrase role="keyword">int</phrase><phrase role="special">)</phrase> <phrase role="keyword">mutable</phrase> <phrase role="special">{</phrase>
199         <phrase role="keyword">int</phrase> <phrase role="identifier">a</phrase><phrase role="special">=</phrase><phrase role="number">0</phrase><phrase role="special">;</phrase>
200         <phrase role="keyword">int</phrase> <phrase role="identifier">b</phrase><phrase role="special">=</phrase><phrase role="number">1</phrase><phrase role="special">;</phrase>
201         <phrase role="keyword">while</phrase><phrase role="special">(</phrase><phrase role="identifier">n</phrase><phrase role="special">--&gt;</phrase><phrase role="number">0</phrase><phrase role="special">){</phrase>
202             <phrase role="keyword">auto</phrase> <phrase role="identifier">result</phrase><phrase role="special">=</phrase><phrase role="identifier">sink</phrase><phrase role="special">(</phrase><phrase role="identifier">a</phrase><phrase role="special">);</phrase>
203             <phrase role="identifier">sink</phrase><phrase role="special">=</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">move</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">get</phrase><phrase role="special">&lt;</phrase><phrase role="number">0</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">result</phrase><phrase role="special">));</phrase>
204             <phrase role="keyword">auto</phrase> <phrase role="identifier">next</phrase><phrase role="special">=</phrase><phrase role="identifier">a</phrase><phrase role="special">+</phrase><phrase role="identifier">b</phrase><phrase role="special">;</phrase>
205             <phrase role="identifier">a</phrase><phrase role="special">=</phrase><phrase role="identifier">b</phrase><phrase role="special">;</phrase>
206             <phrase role="identifier">b</phrase><phrase role="special">=</phrase><phrase role="identifier">next</phrase><phrase role="special">;</phrase>
207         <phrase role="special">}</phrase>
208         <phrase role="keyword">return</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">move</phrase><phrase role="special">(</phrase><phrase role="identifier">sink</phrase><phrase role="special">);</phrase>
209     <phrase role="special">});</phrase>
210 <phrase role="keyword">for</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase><phrase role="special">=</phrase><phrase role="number">0</phrase><phrase role="special">;</phrase><phrase role="identifier">i</phrase><phrase role="special">&lt;</phrase><phrase role="number">10</phrase><phrase role="special">;++</phrase><phrase role="identifier">i</phrase><phrase role="special">){</phrase>
211     <phrase role="keyword">auto</phrase> <phrase role="identifier">result</phrase><phrase role="special">=</phrase><phrase role="identifier">source</phrase><phrase role="special">(</phrase><phrase role="identifier">i</phrase><phrase role="special">);</phrase>
212     <phrase role="identifier">source</phrase><phrase role="special">=</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">move</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">get</phrase><phrase role="special">&lt;</phrase><phrase role="number">0</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">result</phrase><phrase role="special">));</phrase>
213     <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase><phrase role="special">&lt;&lt;</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">get</phrase><phrase role="special">&lt;</phrase><phrase role="number">1</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">result</phrase><phrase role="special">)&lt;&lt;</phrase><phrase role="string">&quot; &quot;</phrase><phrase role="special">;</phrase>
214 <phrase role="special">}</phrase>
215
216 <phrase role="identifier">output</phrase><phrase role="special">:</phrase>
217     <phrase role="number">0</phrase> <phrase role="number">1</phrase> <phrase role="number">1</phrase> <phrase role="number">2</phrase> <phrase role="number">3</phrase> <phrase role="number">5</phrase> <phrase role="number">8</phrase> <phrase role="number">13</phrase> <phrase role="number">21</phrase> <phrase role="number">34</phrase>
218 </programlisting>
219     <para>
220       This simple example demonstrates the basic usage of <emphasis>execution_context</emphasis>
221       as a generator. The context <code><phrase role="identifier">sink</phrase></code>
222       represents the <emphasis>main</emphasis>-context (function <emphasis>main()</emphasis>
223       running). <code><phrase role="identifier">sink</phrase></code> is generated
224       by the framework (first element of lambda's parameter list). Because the state
225       is invalidated (== changed) by each call of <emphasis>execution_context::operator()</emphasis>,
226       the new state of the <emphasis>execution_context</emphasis>, returned by <emphasis>execution_context::operator()</emphasis>,
227       needs to be assigned to <code><phrase role="identifier">sink</phrase></code>
228       after each call.
229     </para>
230     <para>
231       The lambda that calculates the Fibonacci numbers is executed inside the context
232       represented by <code><phrase role="identifier">source</phrase></code>. Calculated
233       Fibonacci numbers are transferred between the two context' via expression
234       <emphasis>sink(a)</emphasis> (and returned by <emphasis>source()</emphasis>).
235       Note that this example represents a <emphasis>generator</emphasis> thus the
236       value transferred into the lambda via <emphasis>source()</emphasis> is not
237       used. Using <emphasis>boost::optional&lt;&gt;</emphasis> as transferred type,
238       might also appropriate to express this fact.
239     </para>
240     <para>
241       The locale variables <code><phrase role="identifier">a</phrase></code>, <code><phrase
242       role="identifier">b</phrase></code> and <code> <phrase role="identifier">next</phrase></code>
243       remain their values during each context switch (<emphasis>yield(a)</emphasis>).
244       This is possible due <code><phrase role="identifier">source</phrase></code>
245       has its own stack and the stack is exchanged by each context switch.
246     </para>
247     <bridgehead renderas="sect3" id="context.ecv2.h1">
248       <phrase id="context.ecv2.parameter_passing"/><link linkend="context.ecv2.parameter_passing">parameter
249       passing</link>
250     </bridgehead>
251     <para>
252       With <code><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase
253       role="keyword">void</phrase><phrase role="special">&gt;</phrase></code> no
254       data will be transferred, only the context switch is executed.
255     </para>
256 <programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">void</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">ctx1</phrase><phrase role="special">([](</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">void</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">ctx2</phrase><phrase role="special">){</phrase>
257             <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">printf</phrase><phrase role="special">(</phrase><phrase role="string">&quot;inside ctx1\n&quot;</phrase><phrase role="special">);</phrase>
258             <phrase role="keyword">return</phrase> <phrase role="identifier">ctx2</phrase><phrase role="special">();</phrase>
259         <phrase role="special">});</phrase>
260 <phrase role="identifier">ctx1</phrase><phrase role="special">();</phrase>
261
262 <phrase role="identifier">output</phrase><phrase role="special">:</phrase>
263     <phrase role="identifier">inside</phrase> <phrase role="identifier">ctx1</phrase>
264 </programlisting>
265     <para>
266       <code><phrase role="identifier">ctx1</phrase><phrase role="special">()</phrase></code>
267       resumes <code><phrase role="identifier">ctx1</phrase></code>, e.g. the lambda
268       passed at the constructor of <code><phrase role="identifier">ctx1</phrase></code>
269       is entered. Argument <code><phrase role="identifier">ctx2</phrase></code> represents
270       the context that has been suspended with the invocation of <code><phrase role="identifier">ctx1</phrase><phrase
271       role="special">()</phrase></code>. When the lambda returns <code><phrase role="identifier">ctx2</phrase></code>,
272       context <code><phrase role="identifier">ctx1</phrase></code> will be terminated
273       while the context represented by <code><phrase role="identifier">ctx2</phrase></code>
274       is resumed, hence the control of execution returns from <code><phrase role="identifier">ctx1</phrase><phrase
275       role="special">()</phrase></code>.
276     </para>
277     <para>
278       The arguments passed to <emphasis>execution_context::operator()</emphasis>,
279       in one context, is passed as the last arguments of the <emphasis>context-function</emphasis>
280       if the context is started for the first time. In all following invocations
281       of <emphasis>execution_context::operator()</emphasis> the arguments passed
282       to <emphasis>execution_context::operator()</emphasis>, in one context, is returned
283       by <emphasis>execution_context::operator()</emphasis> in the other context.
284     </para>
285 <programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">ctx1</phrase><phrase role="special">([](</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">ctx2</phrase><phrase role="special">,</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">j</phrase><phrase role="special">){</phrase>
286             <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">printf</phrase><phrase role="special">(</phrase><phrase role="string">&quot;inside ctx1,j==%d\n&quot;</phrase><phrase role="special">,</phrase><phrase role="identifier">j</phrase><phrase role="special">);</phrase>
287             <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">tie</phrase><phrase role="special">(</phrase><phrase role="identifier">ctx2</phrase><phrase role="special">,</phrase><phrase role="identifier">j</phrase><phrase role="special">)=</phrase><phrase role="identifier">ctx2</phrase><phrase role="special">(</phrase><phrase role="identifier">j</phrase><phrase role="special">+</phrase><phrase role="number">1</phrase><phrase role="special">);</phrase>
288             <phrase role="keyword">return</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">move</phrase><phrase role="special">(</phrase><phrase role="identifier">ctx2</phrase><phrase role="special">);</phrase>
289         <phrase role="special">});</phrase>
290 <phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase><phrase role="special">=</phrase><phrase role="number">1</phrase><phrase role="special">;</phrase>
291 <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">tie</phrase><phrase role="special">(</phrase><phrase role="identifier">ctx1</phrase><phrase role="special">,</phrase><phrase role="identifier">i</phrase><phrase role="special">)=</phrase><phrase role="identifier">ctx1</phrase><phrase role="special">(</phrase><phrase role="identifier">i</phrase><phrase role="special">);</phrase>
292 <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">printf</phrase><phrase role="special">(</phrase><phrase role="string">&quot;i==%d\n&quot;</phrase><phrase role="special">,</phrase><phrase role="identifier">i</phrase><phrase role="special">);</phrase>
293
294 <phrase role="identifier">output</phrase><phrase role="special">:</phrase>
295     <phrase role="identifier">inside</phrase> <phrase role="identifier">ctx1</phrase><phrase role="special">,</phrase><phrase role="identifier">j</phrase><phrase role="special">==</phrase><phrase role="number">1</phrase>
296     <phrase role="identifier">i</phrase><phrase role="special">==</phrase><phrase role="number">2</phrase>
297 </programlisting>
298     <para>
299       <code><phrase role="identifier">ctx1</phrase><phrase role="special">(</phrase><phrase
300       role="identifier">i</phrase><phrase role="special">)</phrase></code> enters
301       the lambda in context <code><phrase role="identifier">ctx1</phrase></code>
302       with argument <code><phrase role="identifier">j</phrase><phrase role="special">=</phrase><phrase
303       role="number">1</phrase></code>. The expression <code><phrase role="identifier">ctx2</phrase><phrase
304       role="special">(</phrase><phrase role="identifier">j</phrase><phrase role="special">+</phrase><phrase
305       role="number">1</phrase><phrase role="special">)</phrase></code> resumes the
306       context represented by <code><phrase role="identifier">ctx2</phrase></code>
307       and transfers back an integer of <code><phrase role="identifier">j</phrase><phrase
308       role="special">+</phrase><phrase role="number">1</phrase></code>. On return
309       of <code><phrase role="identifier">ctx1</phrase><phrase role="special">(</phrase><phrase
310       role="identifier">i</phrase><phrase role="special">)</phrase></code>, the variable
311       <code><phrase role="identifier">i</phrase></code> contains the value of <code><phrase
312       role="identifier">j</phrase><phrase role="special">+</phrase><phrase role="number">1</phrase></code>.
313     </para>
314     <para>
315       If more than one argument has to be transferred, the signature of the context-function
316       is simply extended.
317     </para>
318 <programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">,</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">ctx1</phrase><phrase role="special">([](</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">,</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">ctx2</phrase><phrase role="special">,</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase><phrase role="special">,</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">j</phrase><phrase role="special">){</phrase>
319             <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">printf</phrase><phrase role="special">(</phrase><phrase role="string">&quot;inside ctx1,i==%d,j==%d\n&quot;</phrase><phrase role="special">,</phrase><phrase role="identifier">i</phrase><phrase role="special">,</phrase><phrase role="identifier">j</phrase><phrase role="special">);</phrase>
320             <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">tie</phrase><phrase role="special">(</phrase><phrase role="identifier">ctx2</phrase><phrase role="special">,</phrase><phrase role="identifier">i</phrase><phrase role="special">,</phrase><phrase role="identifier">j</phrase><phrase role="special">)=</phrase><phrase role="identifier">ctx2</phrase><phrase role="special">(</phrase><phrase role="identifier">i</phrase><phrase role="special">+</phrase><phrase role="identifier">j</phrase><phrase role="special">,</phrase><phrase role="identifier">i</phrase><phrase role="special">-</phrase><phrase role="identifier">j</phrase><phrase role="special">);</phrase>
321             <phrase role="keyword">return</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">move</phrase><phrase role="special">(</phrase><phrase role="identifier">ctx2</phrase><phrase role="special">);</phrase>
322         <phrase role="special">});</phrase>
323 <phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase><phrase role="special">=</phrase><phrase role="number">2</phrase><phrase role="special">,</phrase><phrase role="identifier">j</phrase><phrase role="special">=</phrase><phrase role="number">1</phrase><phrase role="special">;</phrase>
324 <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">tie</phrase><phrase role="special">(</phrase><phrase role="identifier">ctx1</phrase><phrase role="special">,</phrase><phrase role="identifier">i</phrase><phrase role="special">,</phrase><phrase role="identifier">j</phrase><phrase role="special">)=</phrase><phrase role="identifier">ctx1</phrase><phrase role="special">(</phrase><phrase role="identifier">i</phrase><phrase role="special">,</phrase><phrase role="identifier">j</phrase><phrase role="special">);</phrase>
325 <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">printf</phrase><phrase role="special">(</phrase><phrase role="string">&quot;i==%d,j==%d\n&quot;</phrase><phrase role="special">,</phrase><phrase role="identifier">i</phrase><phrase role="special">,</phrase><phrase role="identifier">j</phrase><phrase role="special">);</phrase>
326
327 <phrase role="identifier">output</phrase><phrase role="special">:</phrase>
328     <phrase role="identifier">inside</phrase> <phrase role="identifier">ctx1</phrase><phrase role="special">,</phrase><phrase role="identifier">i</phrase><phrase role="special">==</phrase><phrase role="number">2</phrase><phrase role="special">,</phrase><phrase role="identifier">j</phrase><phrase role="special">==</phrase><phrase role="number">1</phrase>
329     <phrase role="identifier">i</phrase><phrase role="special">==</phrase><phrase role="number">3</phrase><phrase role="special">,</phrase><phrase role="identifier">j</phrase><phrase role="special">==</phrase><phrase role="number">1</phrase>
330 </programlisting>
331     <para>
332       For use-cases, that require to transfer data of different type in each direction,
333       <emphasis>boost::variant&lt;&gt;</emphasis> could be used.
334     </para>
335 <programlisting><phrase role="keyword">class</phrase> <phrase role="identifier">X</phrase><phrase role="special">{</phrase>
336 <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
337     <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception_ptr</phrase> <phrase role="identifier">excptr_</phrase><phrase role="special">;</phrase>
338     <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">variant</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">,</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase><phrase role="special">&gt;&gt;</phrase> <phrase role="identifier">ctx_</phrase><phrase role="special">;</phrase>
339
340 <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
341     <phrase role="identifier">X</phrase><phrase role="special">():</phrase>
342         <phrase role="identifier">excptr_</phrase><phrase role="special">(),</phrase>
343         <phrase role="identifier">ctx_</phrase><phrase role="special">([=](</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">variant</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">,</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase><phrase role="special">&gt;&gt;</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">ctx</phrase><phrase role="special">,</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">variant</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">,</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">data</phrase><phrase role="special">){</phrase>
344                 <phrase role="keyword">try</phrase> <phrase role="special">{</phrase>
345                     <phrase role="keyword">for</phrase> <phrase role="special">(;;)</phrase> <phrase role="special">{</phrase>
346                         <phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase><phrase role="special">=</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">get</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">data</phrase><phrase role="special">);</phrase>
347                         <phrase role="identifier">data</phrase><phrase role="special">=</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">lexical_cast</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">i</phrase><phrase role="special">);</phrase>
348                         <phrase role="keyword">auto</phrase> <phrase role="identifier">result</phrase><phrase role="special">=</phrase><phrase role="identifier">ctx</phrase><phrase role="special">(</phrase><phrase role="identifier">data</phrase><phrase role="special">);</phrase>
349                         <phrase role="identifier">ctx</phrase><phrase role="special">=</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">move</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">get</phrase><phrase role="special">&lt;</phrase><phrase role="number">0</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">result</phrase><phrase role="special">));</phrase>
350                         <phrase role="identifier">data</phrase><phrase role="special">=</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">get</phrase><phrase role="special">&lt;</phrase><phrase role="number">1</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">result</phrase><phrase role="special">);</phrase>
351                 <phrase role="special">}</phrase> <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">bad_cast</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;)</phrase> <phrase role="special">{</phrase>
352                     <phrase role="identifier">excptr_</phrase><phrase role="special">=</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">current_exception</phrase><phrase role="special">();</phrase>
353                 <phrase role="special">}</phrase>
354                 <phrase role="keyword">return</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">move</phrase><phrase role="special">(</phrase><phrase role="identifier">ctx</phrase><phrase role="special">);</phrase>
355              <phrase role="special">})</phrase>
356     <phrase role="special">{}</phrase>
357
358     <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">operator</phrase><phrase role="special">()(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase><phrase role="special">){</phrase>
359         <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">variant</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">,</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">data</phrase><phrase role="special">=</phrase><phrase role="identifier">i</phrase><phrase role="special">;</phrase>
360         <phrase role="keyword">auto</phrase> <phrase role="identifier">result</phrase><phrase role="special">=</phrase><phrase role="identifier">ctx_</phrase><phrase role="special">(</phrase><phrase role="identifier">data</phrase><phrase role="special">);</phrase>
361         <phrase role="identifier">ctx_</phrase><phrase role="special">=</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">move</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">get</phrase><phrase role="special">&lt;</phrase><phrase role="number">0</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">result</phrase><phrase role="special">));</phrase>
362         <phrase role="identifier">data</phrase><phrase role="special">=</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">get</phrase><phrase role="special">&lt;</phrase><phrase role="number">1</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">result</phrase><phrase role="special">);</phrase>
363         <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">excptr_</phrase><phrase role="special">){</phrase>
364             <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">rethrow_exception</phrase><phrase role="special">(</phrase><phrase role="identifier">excptr_</phrase><phrase role="special">);</phrase>
365         <phrase role="special">}</phrase>
366         <phrase role="keyword">return</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">get</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">data</phrase><phrase role="special">);</phrase>
367     <phrase role="special">}</phrase>
368 <phrase role="special">};</phrase>
369
370 <phrase role="identifier">X</phrase> <phrase role="identifier">x</phrase><phrase role="special">;</phrase>
371 <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">x</phrase><phrase role="special">(</phrase><phrase role="number">7</phrase><phrase role="special">)</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
372
373 <phrase role="identifier">output</phrase><phrase role="special">:</phrase>
374 <phrase role="number">7</phrase>
375 </programlisting>
376     <para>
377       In the case of unidirectional transfer of data, <emphasis>boost::optional&lt;&gt;</emphasis>
378       or a pointer are appropriate.
379     </para>
380     <bridgehead renderas="sect3" id="context.ecv2.h2">
381       <phrase id="context.ecv2.exception_handling"/><link linkend="context.ecv2.exception_handling">exception
382       handling</link>
383     </bridgehead>
384     <para>
385       If the function executed inside a <emphasis>execution_context</emphasis> emits
386       ans exception, the application is terminated by calling <emphasis>std::terminate()</emphasis>.
387       <emphasis>std::exception_ptr</emphasis> can be used to transfer exceptions
388       between different execution contexts.
389     </para>
390     <important>
391       <para>
392         Do not jump from inside a catch block and then re-throw the exception in
393         another execution context.
394       </para>
395     </important>
396     <anchor id="ecv2_ontop"/>
397     <bridgehead renderas="sect3" id="context.ecv2.h3">
398       <phrase id="context.ecv2.executing_function_on_top_of_a_context"/><link linkend="context.ecv2.executing_function_on_top_of_a_context">Executing
399       function on top of a context</link>
400     </bridgehead>
401     <para>
402       Sometimes it is useful to execute a new function on top of a resumed context.
403       For this purpose <emphasis>execution_context::operator()</emphasis> with first
404       argument <code><phrase role="identifier">exec_ontop_arg</phrase></code> has
405       to be used. The function passed as argument must return a tuple of execution_context
406       and arguments.
407     </para>
408 <programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">f1</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">ctx</phrase><phrase role="special">,</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">data</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
409     <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;f1: entered first time: &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">data</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
410     <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">tie</phrase><phrase role="special">(</phrase><phrase role="identifier">ctx</phrase><phrase role="special">,</phrase><phrase role="identifier">data</phrase><phrase role="special">)=</phrase><phrase role="identifier">ctx</phrase><phrase role="special">(</phrase><phrase role="identifier">data</phrase><phrase role="special">+</phrase><phrase role="number">1</phrase><phrase role="special">);</phrase>
411     <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;f1: entered second time: &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">data</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
412     <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">tie</phrase><phrase role="special">(</phrase><phrase role="identifier">ctx</phrase><phrase role="special">,</phrase><phrase role="identifier">data</phrase><phrase role="special">)=</phrase><phrase role="identifier">ctx</phrase><phrase role="special">(</phrase><phrase role="identifier">data</phrase><phrase role="special">+</phrase><phrase role="number">1</phrase><phrase role="special">);</phrase>
413     <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;f1: entered third time: &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">data</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
414     <phrase role="keyword">return</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">move</phrase><phrase role="special">(</phrase><phrase role="identifier">ctx</phrase><phrase role="special">);</phrase>
415 <phrase role="special">}</phrase>
416
417 <phrase role="keyword">int</phrase> <phrase role="identifier">f2</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">data</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
418     <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;f2: entered: &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">data</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
419     <phrase role="keyword">return</phrase> <phrase role="special">-</phrase><phrase role="number">1</phrase><phrase role="special">;</phrase>
420 <phrase role="special">}</phrase>
421
422 <phrase role="keyword">int</phrase> <phrase role="identifier">data</phrase><phrase role="special">=</phrase><phrase role="number">0</phrase><phrase role="special">;</phrase>
423 <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">ctx</phrase><phrase role="special">(</phrase><phrase role="identifier">f1</phrase><phrase role="special">);</phrase>
424 <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">tie</phrase><phrase role="special">(</phrase><phrase role="identifier">ctx</phrase><phrase role="special">,</phrase><phrase role="identifier">data</phrase><phrase role="special">)=</phrase><phrase role="identifier">ctx</phrase><phrase role="special">(</phrase><phrase role="identifier">data</phrase><phrase role="special">+</phrase><phrase role="number">1</phrase><phrase role="special">);</phrase>
425 <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;f1: returned first time: &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">data</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
426 <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">tie</phrase><phrase role="special">(</phrase><phrase role="identifier">ctx</phrase><phrase role="special">,</phrase><phrase role="identifier">data</phrase><phrase role="special">)=</phrase><phrase role="identifier">ctx</phrase><phrase role="special">(</phrase><phrase role="identifier">data</phrase><phrase role="special">+</phrase><phrase role="number">1</phrase><phrase role="special">);</phrase>
427 <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;f1: returned second time: &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">data</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
428 <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">tie</phrase><phrase role="special">(</phrase><phrase role="identifier">ctx</phrase><phrase role="special">,</phrase><phrase role="identifier">data</phrase><phrase role="special">)=</phrase><phrase role="identifier">ctx</phrase><phrase role="special">(</phrase><phrase role="identifier">ctx</phrase><phrase role="special">::</phrase><phrase role="identifier">exec_ontop_arg</phrase><phrase role="special">,</phrase><phrase role="identifier">f2</phrase><phrase role="special">,</phrase><phrase role="identifier">data</phrase><phrase role="special">+</phrase><phrase role="number">1</phrase><phrase role="special">);</phrase>
429
430 <phrase role="identifier">output</phrase><phrase role="special">:</phrase>
431     <phrase role="identifier">f1</phrase><phrase role="special">:</phrase> <phrase role="identifier">entered</phrase> <phrase role="identifier">first</phrase> <phrase role="identifier">time</phrase><phrase role="special">:</phrase> <phrase role="number">1</phrase>
432     <phrase role="identifier">f1</phrase><phrase role="special">:</phrase> <phrase role="identifier">returned</phrase> <phrase role="identifier">first</phrase> <phrase role="identifier">time</phrase><phrase role="special">:</phrase> <phrase role="number">2</phrase>
433     <phrase role="identifier">f1</phrase><phrase role="special">:</phrase> <phrase role="identifier">entered</phrase> <phrase role="identifier">second</phrase> <phrase role="identifier">time</phrase><phrase role="special">:</phrase> <phrase role="number">3</phrase>
434     <phrase role="identifier">f1</phrase><phrase role="special">:</phrase> <phrase role="identifier">returned</phrase> <phrase role="identifier">second</phrase> <phrase role="identifier">time</phrase><phrase role="special">:</phrase> <phrase role="number">4</phrase>
435     <phrase role="identifier">f2</phrase><phrase role="special">:</phrase> <phrase role="identifier">entered</phrase><phrase role="special">:</phrase> <phrase role="number">5</phrase>
436     <phrase role="identifier">f1</phrase><phrase role="special">:</phrase> <phrase role="identifier">entered</phrase> <phrase role="identifier">third</phrase> <phrase role="identifier">time</phrase><phrase role="special">:</phrase> <phrase role="special">-</phrase><phrase role="number">1</phrase>
437 </programlisting>
438     <para>
439       The expression <code><phrase role="identifier">ctx</phrase><phrase role="special">(</phrase><phrase
440       role="identifier">ctx</phrase><phrase role="special">::</phrase><phrase role="identifier">exec_ontop_arg</phrase><phrase
441       role="special">,</phrase><phrase role="identifier">f2</phrase><phrase role="special">,</phrase><phrase
442       role="identifier">data</phrase><phrase role="special">+</phrase><phrase role="number">1</phrase><phrase
443       role="special">)</phrase></code> executes <code><phrase role="identifier">f2</phrase><phrase
444       role="special">()</phrase></code> on top of context <code><phrase role="identifier">ctx</phrase></code>,
445       e.g. an additional stack frame is allocated on top of the context stack (in
446       front of <code><phrase role="identifier">f1</phrase><phrase role="special">()</phrase></code>).
447       <code><phrase role="identifier">f2</phrase><phrase role="special">()</phrase></code>
448       returns argument <code><phrase role="special">-</phrase><phrase role="number">1</phrase></code>
449       that will returned by the second invocation of <code><phrase role="identifier">ctx</phrase><phrase
450       role="special">(</phrase><phrase role="identifier">data</phrase><phrase role="special">+</phrase><phrase
451       role="number">1</phrase><phrase role="special">)</phrase></code> in <code><phrase
452       role="identifier">f1</phrase><phrase role="special">()</phrase></code>. [/
453       Another option is to execute a function on top of the context that throws an
454       exception. The thrown exception is catched and re-thrown as nested exception
455       of <emphasis>ontop_error</emphasis> from <emphasis>execution_context::operator()</emphasis>.
456       <emphasis>ontop_error</emphasis> gives access to the context that has resumed
457       the current context.
458     </para>
459 <programlisting><phrase role="keyword">struct</phrase> <phrase role="identifier">my_exception</phrase> <phrase role="special">:</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">runtime_error</phrase> <phrase role="special">{</phrase>
460     <phrase role="identifier">my_exception</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">what</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase>
461         <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">runtime_error</phrase><phrase role="special">{</phrase> <phrase role="identifier">what</phrase> <phrase role="special">}</phrase> <phrase role="special">{</phrase>
462     <phrase role="special">}</phrase>
463 <phrase role="special">};</phrase>
464
465 <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">void</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">ctx</phrase><phrase role="special">([](</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">void</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">ctx</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
466     <phrase role="keyword">for</phrase> <phrase role="special">(;;)</phrase> <phrase role="special">{</phrase>
467         <phrase role="keyword">try</phrase> <phrase role="special">{</phrase>
468                 <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;entered&quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
469                 <phrase role="identifier">ctx</phrase> <phrase role="special">=</phrase> <phrase role="identifier">ctx</phrase><phrase role="special">();</phrase>
470             <phrase role="special">}</phrase>
471         <phrase role="special">}</phrase> <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">ontop_error</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">e</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
472             <phrase role="keyword">try</phrase> <phrase role="special">{</phrase>
473                 <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">rethrow_if_nested</phrase><phrase role="special">(</phrase> <phrase role="identifier">e</phrase><phrase role="special">);</phrase>
474             <phrase role="special">}</phrase> <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="identifier">my_exception</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">ex</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
475                 <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;my_exception: &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">ex</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
476             <phrase role="special">}</phrase>
477             <phrase role="keyword">return</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">get_context</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">void</phrase> <phrase role="special">&gt;();</phrase>
478         <phrase role="special">}</phrase>
479     <phrase role="special">}</phrase>
480     <phrase role="keyword">return</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">move</phrase><phrase role="special">(</phrase> <phrase role="identifier">ctx</phrase><phrase role="special">);</phrase>
481 <phrase role="special">});</phrase>
482 <phrase role="identifier">ctx</phrase> <phrase role="special">=</phrase> <phrase role="identifier">ctx</phrase><phrase role="special">();</phrase>
483 <phrase role="identifier">ctx</phrase> <phrase role="special">=</phrase> <phrase role="identifier">ctx</phrase><phrase role="special">();</phrase>
484 <phrase role="identifier">ctx</phrase> <phrase role="special">=</phrase> <phrase role="identifier">ctx</phrase><phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">exec_ontop_arg</phrase><phrase role="special">,[](){</phrase> <phrase role="keyword">throw</phrase> <phrase role="identifier">my_exception</phrase><phrase role="special">{</phrase> <phrase role="string">&quot;abc&quot;</phrase> <phrase role="special">};</phrase> <phrase role="special">});</phrase>
485
486 <phrase role="identifier">output</phrase><phrase role="special">:</phrase>
487     <phrase role="identifier">entered</phrase>
488     <phrase role="identifier">entered</phrase>
489     <phrase role="identifier">my_exception</phrase><phrase role="special">:</phrase> <phrase role="identifier">abc</phrase>
490 </programlisting>
491     <para>
492       In this exception <code><phrase role="identifier">my_exception</phrase></code>
493       is throw from a function invoked ontop of context <code><phrase role="identifier">ctx</phrase></code>
494       and catched inside the <code><phrase role="keyword">for</phrase></code>-loop.
495     </para>
496     <bridgehead renderas="sect3" id="context.ecv2.h4">
497       <phrase id="context.ecv2.stack_unwinding"/><link linkend="context.ecv2.stack_unwinding">stack
498       unwinding</link>
499     </bridgehead>
500     <para>
501       On construction of <emphasis>execution_context</emphasis> a stack is allocated.
502       If the <emphasis>context-function</emphasis> returns the stack will be destructed.
503       If the <emphasis>context-function</emphasis> has not yet returned and the destructor
504       of an valid <emphasis>execution_context</emphasis> instance (e.g. <emphasis>execution_context::operator
505       bool()</emphasis> returns <code><phrase role="keyword">true</phrase></code>)
506       is called, the stack will be destructed too.
507     </para>
508     <important>
509       <para>
510         Code executed by <emphasis>context-function</emphasis> must not prevent the
511         propagation of the <emphasis>detail::forced_unwind</emphasis> exception.
512         Absorbing that exception will cause stack unwinding to fail. Thus, any code
513         that catches all exceptions must re-throw any pending <emphasis>detail::forced_unwind</emphasis>
514         exception.
515       </para>
516     </important>
517     <anchor id="ecv2_prealloc"/>
518     <bridgehead renderas="sect3" id="context.ecv2.h5">
519       <phrase id="context.ecv2.allocating_control_structures_on_top_of_stack"/><link
520       linkend="context.ecv2.allocating_control_structures_on_top_of_stack">allocating
521       control structures on top of stack</link>
522     </bridgehead>
523     <para>
524       Allocating control structures on top of the stack requires to allocated the
525       <emphasis>stack_context</emphasis> and create the control structure with placement
526       new before <emphasis>execution_context</emphasis> is created.
527     </para>
528     <note>
529       <para>
530         The user is responsible for destructing the control structure at the top
531         of the stack.
532       </para>
533     </note>
534 <programlisting><phrase role="comment">// stack-allocator used for (de-)allocating stack</phrase>
535 <phrase role="identifier">fixedsize_stack</phrase> <phrase role="identifier">salloc</phrase><phrase role="special">(</phrase><phrase role="number">4048</phrase><phrase role="special">);</phrase>
536 <phrase role="comment">// allocate stack space</phrase>
537 <phrase role="identifier">stack_context</phrase> <phrase role="identifier">sctx</phrase><phrase role="special">(</phrase><phrase role="identifier">salloc</phrase><phrase role="special">.</phrase><phrase role="identifier">allocate</phrase><phrase role="special">());</phrase>
538 <phrase role="comment">// reserve space for control structure on top of the stack</phrase>
539 <phrase role="keyword">void</phrase> <phrase role="special">*</phrase> <phrase role="identifier">sp</phrase><phrase role="special">=</phrase><phrase role="keyword">static_cast</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">char</phrase><phrase role="special">*&gt;(</phrase><phrase role="identifier">sctx</phrase><phrase role="special">.</phrase><phrase role="identifier">sp</phrase><phrase role="special">)-</phrase><phrase role="keyword">sizeof</phrase><phrase role="special">(</phrase><phrase role="identifier">my_control_structure</phrase><phrase role="special">);</phrase>
540 <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">size</phrase><phrase role="special">=</phrase><phrase role="identifier">sctx</phrase><phrase role="special">.</phrase><phrase role="identifier">size</phrase><phrase role="special">-</phrase><phrase role="keyword">sizeof</phrase><phrase role="special">(</phrase><phrase role="identifier">my_control_structure</phrase><phrase role="special">);</phrase>
541 <phrase role="comment">// placement new creates control structure on reserved space</phrase>
542 <phrase role="identifier">my_control_structure</phrase> <phrase role="special">*</phrase> <phrase role="identifier">cs</phrase><phrase role="special">=</phrase><phrase role="keyword">new</phrase><phrase role="special">(</phrase><phrase role="identifier">sp</phrase><phrase role="special">)</phrase><phrase role="identifier">my_control_structure</phrase><phrase role="special">(</phrase><phrase role="identifier">sp</phrase><phrase role="special">,</phrase><phrase role="identifier">size</phrase><phrase role="special">,</phrase><phrase role="identifier">sctx</phrase><phrase role="special">,</phrase><phrase role="identifier">salloc</phrase><phrase role="special">);</phrase>
543 <phrase role="special">...</phrase>
544 <phrase role="comment">// destructing the control structure</phrase>
545 <phrase role="identifier">cs</phrase><phrase role="special">-&gt;~</phrase><phrase role="identifier">my_control_structure</phrase><phrase role="special">();</phrase>
546 <phrase role="special">...</phrase>
547 <phrase role="keyword">struct</phrase> <phrase role="identifier">my_control_structure</phrase>  <phrase role="special">{</phrase>
548     <phrase role="comment">// captured context</phrase>
549     <phrase role="identifier">execution_context</phrase> <phrase role="identifier">cctx</phrase><phrase role="special">;</phrase>
550
551     <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">StackAllocator</phrase> <phrase role="special">&gt;</phrase>
552     <phrase role="identifier">my_control_structure</phrase><phrase role="special">(</phrase><phrase role="keyword">void</phrase> <phrase role="special">*</phrase> <phrase role="identifier">sp</phrase><phrase role="special">,</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">size</phrase><phrase role="special">,</phrase><phrase role="identifier">stack_context</phrase> <phrase role="identifier">sctx</phrase><phrase role="special">,</phrase><phrase role="identifier">StackAllocator</phrase> <phrase role="identifier">salloc</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase>
553         <phrase role="comment">// create captured context</phrase>
554         <phrase role="identifier">cctx</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">allocator_arg</phrase><phrase role="special">,</phrase><phrase role="identifier">preallocated</phrase><phrase role="special">(</phrase><phrase role="identifier">sp</phrase><phrase role="special">,</phrase><phrase role="identifier">size</phrase><phrase role="special">,</phrase><phrase role="identifier">sctx</phrase><phrase role="special">),</phrase><phrase role="identifier">salloc</phrase><phrase role="special">,</phrase><phrase role="identifier">entry_func</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
555     <phrase role="special">}</phrase>
556     <phrase role="special">...</phrase>
557 <phrase role="special">};</phrase>
558 </programlisting>
559     <bridgehead renderas="sect3" id="context.ecv2.h6">
560       <phrase id="context.ecv2.inverting_the_control_flow"/><link linkend="context.ecv2.inverting_the_control_flow">inverting
561       the control flow</link>
562     </bridgehead>
563 <programlisting><phrase role="comment">/*
564  * grammar:
565  *   P ---&gt; E '\0'
566  *   E ---&gt; T {('+'|'-') T}
567  *   T ---&gt; S {('*'|'/') S}
568  *   S ---&gt; digit | '(' E ')'
569  */</phrase>
570 <phrase role="keyword">class</phrase> <phrase role="identifier">Parser</phrase><phrase role="special">{</phrase>
571     <phrase role="comment">// implementation omitted; see examples directory</phrase>
572 <phrase role="special">};</phrase>
573
574 <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">istringstream</phrase> <phrase role="identifier">is</phrase><phrase role="special">(</phrase><phrase role="string">&quot;1+1&quot;</phrase><phrase role="special">);</phrase>
575 <phrase role="keyword">bool</phrase> <phrase role="identifier">done</phrase><phrase role="special">=</phrase><phrase role="keyword">false</phrase><phrase role="special">;</phrase>
576 <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception_ptr</phrase> <phrase role="identifier">except</phrase><phrase role="special">;</phrase>
577
578 <phrase role="comment">// execute parser in new execution context</phrase>
579 <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">char</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">source</phrase><phrase role="special">(</phrase>
580         <phrase role="special">[&amp;</phrase><phrase role="identifier">is</phrase><phrase role="special">,&amp;</phrase><phrase role="identifier">done</phrase><phrase role="special">,&amp;</phrase><phrase role="identifier">except</phrase><phrase role="special">](</phrase><phrase role="identifier">ctx</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">char</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">sink</phrase><phrase role="special">,</phrase><phrase role="keyword">char</phrase><phrase role="special">){</phrase>
581         <phrase role="comment">// create parser with callback function</phrase>
582         <phrase role="identifier">Parser</phrase> <phrase role="identifier">p</phrase><phrase role="special">(</phrase> <phrase role="identifier">is</phrase><phrase role="special">,</phrase>
583                   <phrase role="special">[&amp;</phrase><phrase role="identifier">sink</phrase><phrase role="special">](</phrase><phrase role="keyword">char</phrase> <phrase role="identifier">ch</phrase><phrase role="special">){</phrase>
584                         <phrase role="comment">// resume main execution context</phrase>
585                         <phrase role="keyword">auto</phrase> <phrase role="identifier">result</phrase><phrase role="special">=</phrase><phrase role="identifier">sink</phrase><phrase role="special">(</phrase><phrase role="identifier">ch</phrase><phrase role="special">);</phrase>
586                         <phrase role="identifier">sink</phrase><phrase role="special">=</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">move</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">get</phrase><phrase role="special">&lt;</phrase><phrase role="number">0</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">result</phrase><phrase role="special">));</phrase>
587                 <phrase role="special">});</phrase>
588             <phrase role="keyword">try</phrase> <phrase role="special">{</phrase>
589                 <phrase role="comment">// start recursive parsing</phrase>
590                 <phrase role="identifier">p</phrase><phrase role="special">.</phrase><phrase role="identifier">run</phrase><phrase role="special">();</phrase>
591             <phrase role="special">}</phrase> <phrase role="keyword">catch</phrase> <phrase role="special">(...)</phrase> <phrase role="special">{</phrase>
592                 <phrase role="comment">// store other exceptions in exception-pointer</phrase>
593                 <phrase role="identifier">except</phrase><phrase role="special">=</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">current_exception</phrase><phrase role="special">();</phrase>
594             <phrase role="special">}</phrase>
595             <phrase role="comment">// set termination flag</phrase>
596             <phrase role="identifier">done</phrase><phrase role="special">=</phrase><phrase role="keyword">true</phrase><phrase role="special">;</phrase>
597             <phrase role="comment">// resume main execution context</phrase>
598             <phrase role="keyword">return</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">move</phrase><phrase role="special">(</phrase><phrase role="identifier">sink</phrase><phrase role="special">);</phrase>
599         <phrase role="special">});</phrase>
600
601 <phrase role="comment">// user-code pulls parsed data from parser</phrase>
602 <phrase role="comment">// invert control flow</phrase>
603 <phrase role="keyword">auto</phrase> <phrase role="identifier">result</phrase><phrase role="special">=</phrase><phrase role="identifier">source</phrase><phrase role="special">(</phrase><phrase role="char">'\0'</phrase><phrase role="special">);</phrase>
604 <phrase role="identifier">source</phrase><phrase role="special">=</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">move</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">get</phrase><phrase role="special">&lt;</phrase><phrase role="number">0</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">result</phrase><phrase role="special">));</phrase>
605 <phrase role="keyword">char</phrase> <phrase role="identifier">c</phrase><phrase role="special">=</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">get</phrase><phrase role="special">&lt;</phrase><phrase role="number">1</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">result</phrase><phrase role="special">);</phrase>
606 <phrase role="keyword">if</phrase> <phrase role="special">(</phrase><phrase role="identifier">except</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
607     <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">rethrow_exception</phrase><phrase role="special">(</phrase><phrase role="identifier">except</phrase><phrase role="special">);</phrase>
608 <phrase role="special">}</phrase>
609 <phrase role="keyword">while</phrase><phrase role="special">(!</phrase><phrase role="identifier">done</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
610     <phrase role="identifier">printf</phrase><phrase role="special">(</phrase><phrase role="string">&quot;Parsed: %c\n&quot;</phrase><phrase role="special">,</phrase><phrase role="identifier">c</phrase><phrase role="special">);</phrase>
611     <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">tie</phrase><phrase role="special">(</phrase><phrase role="identifier">source</phrase><phrase role="special">,</phrase><phrase role="identifier">c</phrase><phrase role="special">)=</phrase><phrase role="identifier">source</phrase><phrase role="special">(</phrase><phrase role="char">'\0'</phrase><phrase role="special">);</phrase>
612     <phrase role="keyword">if</phrase> <phrase role="special">(</phrase><phrase role="identifier">except</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
613         <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">rethrow_exception</phrase><phrase role="special">(</phrase><phrase role="identifier">except</phrase><phrase role="special">);</phrase>
614     <phrase role="special">}</phrase>
615 <phrase role="special">}</phrase>
616
617 <phrase role="identifier">output</phrase><phrase role="special">:</phrase>
618     <phrase role="identifier">Parsed</phrase><phrase role="special">:</phrase> <phrase role="number">1</phrase>
619     <phrase role="identifier">Parsed</phrase><phrase role="special">:</phrase> <phrase role="special">+</phrase>
620     <phrase role="identifier">Parsed</phrase><phrase role="special">:</phrase> <phrase role="number">1</phrase>
621 </programlisting>
622     <para>
623       In this example a recursive descent parser uses a callback to emit a newly
624       passed symbol. Using <emphasis>execution_context</emphasis> the control flow
625       can be inverted, e.g. the user-code pulls parsed symbols from the parser -
626       instead to get pushed from the parser (via callback).
627     </para>
628     <para>
629       The data (character) is transferred between the two <emphasis>execution_context</emphasis>.
630     </para>
631     <para>
632       If the code executed by <emphasis>execution_context</emphasis> emits an exception,
633       the application is terminated. <emphasis>std::exception_ptr</emphasis> can
634       be used to transfer exceptions between different execution contexts.
635     </para>
636     <para>
637       Sometimes it is necessary to unwind the stack of an unfinished context to destroy
638       local stack variables so they can release allocated resources (RAII pattern).
639       The user is responsible for this task.
640     </para>
641     <bridgehead renderas="sect3" id="context.ecv2.h7">
642       <phrase id="context.ecv2.class__code__phrase_role__identifier__execution_context__phrase___code_"/><link
643       linkend="context.ecv2.class__code__phrase_role__identifier__execution_context__phrase___code_">Class
644       <code><phrase role="identifier">execution_context</phrase></code></link>
645     </bridgehead>
646 <programlisting><phrase role="keyword">struct</phrase> <phrase role="identifier">exec_ontop_arg_t</phrase> <phrase role="special">{};</phrase>
647 <phrase role="keyword">const</phrase> <phrase role="identifier">exec_ontop_arg_t</phrase> <phrase role="identifier">exec_ontop_arg</phrase><phrase role="special">{};</phrase>
648
649 <phrase role="keyword">class</phrase> <phrase role="identifier">ontop_error</phrase> <phrase role="special">{</phrase>
650 <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
651     <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="special">...</phrase> <phrase role="identifier">Args</phrase> <phrase role="special">&gt;</phrase>
652     <phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">Args</phrase> <phrase role="special">...</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">get_context</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
653 <phrase role="special">}</phrase>
654
655 <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="special">...</phrase> <phrase role="identifier">Args</phrase> <phrase role="special">&gt;</phrase>
656 <phrase role="keyword">class</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="special">{</phrase>
657 <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
658     <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Fn</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="special">...</phrase> <phrase role="identifier">Params</phrase> <phrase role="special">&gt;</phrase>
659     <phrase role="identifier">execution_context</phrase><phrase role="special">(</phrase> <phrase role="identifier">Fn</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">fn</phrase><phrase role="special">,</phrase> <phrase role="identifier">Params</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="special">...</phrase> <phrase role="identifier">params</phrase><phrase role="special">);</phrase>
660
661     <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">StackAlloc</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Fn</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="special">...</phrase> <phrase role="identifier">Params</phrase> <phrase role="special">&gt;</phrase>
662     <phrase role="identifier">execution_context</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">allocator_arg_t</phrase><phrase role="special">,</phrase> <phrase role="identifier">StackAlloc</phrase> <phrase role="identifier">salloc</phrase><phrase role="special">,</phrase> <phrase role="identifier">Fn</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">fn</phrase><phrase role="special">,</phrase> <phrase role="identifier">Params</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="special">...</phrase> <phrase role="identifier">params</phrase><phrase role="special">);</phrase>
663
664     <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">StackAlloc</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Fn</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="special">...</phrase> <phrase role="identifier">Params</phrase> <phrase role="special">&gt;</phrase>
665     <phrase role="identifier">execution_context</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">allocator_arg_t</phrase><phrase role="special">,</phrase> <phrase role="identifier">preallocated</phrase> <phrase role="identifier">palloc</phrase><phrase role="special">,</phrase> <phrase role="identifier">StackAlloc</phrase> <phrase role="identifier">salloc</phrase><phrase role="special">,</phrase> <phrase role="identifier">Fn</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">fn</phrase><phrase role="special">,</phrase> <phrase role="identifier">Params</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="special">...</phrase> <phrase role="identifier">params</phrase><phrase role="special">);</phrase>
666
667     <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Fn</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="special">...</phrase> <phrase role="identifier">Params</phrase> <phrase role="special">&gt;</phrase>
668     <phrase role="identifier">execution_context</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">allocator_arg_t</phrase><phrase role="special">,</phrase> <phrase role="identifier">segemented_stack</phrase><phrase role="special">,</phrase> <phrase role="identifier">Fn</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">fn</phrase><phrase role="special">,</phrase> <phrase role="identifier">Params</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="special">...</phrase> <phrase role="identifier">params</phrase><phrase role="special">)</phrase> <phrase role="special">=</phrase> <phrase role="keyword">delete</phrase><phrase role="special">;</phrase>
669
670     <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Fn</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="special">...</phrase> <phrase role="identifier">Params</phrase> <phrase role="special">&gt;</phrase>
671     <phrase role="identifier">execution_context</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">allocator_arg_t</phrase><phrase role="special">,</phrase> <phrase role="identifier">preallocated</phrase> <phrase role="identifier">palloc</phrase><phrase role="special">,</phrase> <phrase role="identifier">segmented</phrase><phrase role="special">,</phrase> <phrase role="identifier">Fn</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">fn</phrase><phrase role="special">,</phrase> <phrase role="identifier">Params</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="special">...</phrase> <phrase role="identifier">params</phrase><phrase role="special">)=</phrase> <phrase role="keyword">delete</phrase><phrase role="special">;</phrase>
672
673     <phrase role="special">~</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">();</phrase>
674
675     <phrase role="identifier">execution_context</phrase><phrase role="special">(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
676     <phrase role="identifier">execution_context</phrase> <phrase role="special">&amp;</phrase> <phrase role="keyword">operator</phrase><phrase role="special">=(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
677
678     <phrase role="identifier">execution_context</phrase><phrase role="special">(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">noexcept</phrase> <phrase role="special">=</phrase> <phrase role="keyword">delete</phrase><phrase role="special">;</phrase>
679     <phrase role="identifier">execution_context</phrase> <phrase role="special">&amp;</phrase> <phrase role="keyword">operator</phrase><phrase role="special">=(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">noexcept</phrase> <phrase role="special">=</phrase> <phrase role="keyword">delete</phrase><phrase role="special">;</phrase>
680
681     <phrase role="keyword">explicit</phrase> <phrase role="keyword">operator</phrase> <phrase role="keyword">bool</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
682     <phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">!()</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
683
684     <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">tuple</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">execution_context</phrase><phrase role="special">,</phrase> <phrase role="identifier">Args</phrase> <phrase role="special">...</phrase> <phrase role="special">&gt;</phrase> <phrase role="keyword">operator</phrase><phrase role="special">()(</phrase> <phrase role="identifier">Args</phrase> <phrase role="special">...</phrase> <phrase role="identifier">args</phrase><phrase role="special">);</phrase>
685
686     <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Fn</phrase> <phrase role="special">&gt;</phrase>
687     <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">tuple</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">execution_context</phrase><phrase role="special">,</phrase> <phrase role="identifier">Args</phrase> <phrase role="special">...</phrase> <phrase role="special">&gt;</phrase> <phrase role="keyword">operator</phrase><phrase role="special">()(</phrase> <phrase role="identifier">exec_ontop_arg_t</phrase><phrase role="special">,</phrase> <phrase role="identifier">Fn</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">fn</phrase><phrase role="special">,</phrase> <phrase role="identifier">Args</phrase> <phrase role="special">...</phrase> <phrase role="identifier">args</phrase><phrase role="special">);</phrase>
688
689     <phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">==(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
690
691     <phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">!=(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
692
693     <phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">&lt;(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
694
695     <phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">&gt;(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
696
697     <phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">&lt;=(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
698
699     <phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">&gt;=(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
700
701     <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">charT</phrase><phrase role="special">,</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">traitsT</phrase> <phrase role="special">&gt;</phrase>
702     <phrase role="keyword">friend</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">basic_ostream</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">charT</phrase><phrase role="special">,</phrase> <phrase role="identifier">traitsT</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&amp;</phrase>
703     <phrase role="keyword">operator</phrase><phrase role="special">&lt;&lt;(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">basic_ostream</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">charT</phrase><phrase role="special">,</phrase> <phrase role="identifier">traitsT</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&amp;</phrase> <phrase role="identifier">os</phrase><phrase role="special">,</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">);</phrase>
704 <phrase role="special">};</phrase>
705 </programlisting>
706     <para>
707       <bridgehead renderas="sect4" id="ecv2_constructor_bridgehead">
708   <phrase id="ecv2_constructor"/>
709   <link linkend="ecv2_constructor">Constructor</link>
710 </bridgehead>
711     </para>
712 <programlisting><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Fn</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="special">...</phrase> <phrase role="identifier">Params</phrase> <phrase role="special">&gt;</phrase>
713 <phrase role="identifier">execution_context</phrase><phrase role="special">(</phrase> <phrase role="identifier">Fn</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">fn</phrase><phrase role="special">,</phrase> <phrase role="identifier">Params</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="special">...</phrase> <phrase role="identifier">params</phrase><phrase role="special">);</phrase>
714
715 <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">StackAlloc</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Fn</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="special">...</phrase> <phrase role="identifier">Params</phrase> <phrase role="special">&gt;</phrase>
716 <phrase role="identifier">execution_context</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">allocator_arg_t</phrase><phrase role="special">,</phrase> <phrase role="identifier">StackAlloc</phrase> <phrase role="identifier">salloc</phrase><phrase role="special">,</phrase> <phrase role="identifier">Fn</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">fn</phrase><phrase role="special">,</phrase> <phrase role="identifier">Params</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="special">...</phrase> <phrase role="identifier">params</phrase><phrase role="special">);</phrase>
717
718 <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">StackAlloc</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Fn</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="special">...</phrase> <phrase role="identifier">Params</phrase> <phrase role="special">&gt;</phrase>
719 <phrase role="identifier">execution_context</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">allocator_arg_t</phrase><phrase role="special">,</phrase> <phrase role="identifier">preallocated</phrase> <phrase role="identifier">palloc</phrase><phrase role="special">,</phrase> <phrase role="identifier">StackAlloc</phrase> <phrase role="identifier">salloc</phrase><phrase role="special">,</phrase> <phrase role="identifier">Fn</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">fn</phrase><phrase role="special">,</phrase> <phrase role="identifier">Params</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="special">...</phrase> <phrase role="identifier">params</phrase><phrase role="special">);</phrase>
720 </programlisting>
721     <variablelist>
722       <title></title>
723       <varlistentry>
724         <term>Effects:</term>
725         <listitem>
726           <para>
727             Creates a new execution context and prepares the context to execute
728             <code><phrase role="identifier">fn</phrase></code>. <code><phrase role="identifier">fixedsize_stack</phrase></code>
729             is used as default stack allocator (stack size == fixedsize_stack::traits::default_size()).
730             The constructor with argument type <code><phrase role="identifier">preallocated</phrase></code>,
731             is used to create a user defined data <link linkend="ecv2_prealloc">(for
732             instance additional control structures)</link> on top of the stack.
733           </para>
734         </listitem>
735       </varlistentry>
736     </variablelist>
737     <para>
738       <bridgehead renderas="sect4" id="ecv2_destructor destructor_bridgehead">
739   <phrase id="ecv2_destructor destructor"/>
740   <link linkend="ecv2_destructor
741       destructor">Destructor</link>
742 </bridgehead>
743     </para>
744 <programlisting><phrase role="special">~</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">();</phrase>
745 </programlisting>
746     <variablelist>
747       <title></title>
748       <varlistentry>
749         <term>Effects:</term>
750         <listitem>
751           <para>
752             Destructs the associated stack if <code><phrase role="special">*</phrase><phrase
753             role="keyword">this</phrase></code> is a valid context, e.g. <emphasis>execution_context::operator
754             bool()</emphasis> returns <code><phrase role="keyword">true</phrase></code>.
755           </para>
756         </listitem>
757       </varlistentry>
758       <varlistentry>
759         <term>Throws:</term>
760         <listitem>
761           <para>
762             Nothing.
763           </para>
764         </listitem>
765       </varlistentry>
766     </variablelist>
767     <para>
768       <bridgehead renderas="sect4" id="ecv2_move constructor_bridgehead">
769   <phrase id="ecv2_move constructor"/>
770   <link linkend="ecv2_move constructor">Move
771       constructor</link>
772 </bridgehead>
773     </para>
774 <programlisting><phrase role="identifier">execution_context</phrase><phrase role="special">(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
775 </programlisting>
776     <variablelist>
777       <title></title>
778       <varlistentry>
779         <term>Effects:</term>
780         <listitem>
781           <para>
782             Moves underlying capture record to <code><phrase role="special">*</phrase><phrase
783             role="keyword">this</phrase></code>.
784           </para>
785         </listitem>
786       </varlistentry>
787       <varlistentry>
788         <term>Throws:</term>
789         <listitem>
790           <para>
791             Nothing.
792           </para>
793         </listitem>
794       </varlistentry>
795     </variablelist>
796     <para>
797       <bridgehead renderas="sect4" id="ecv2_move assignment_bridgehead">
798   <phrase id="ecv2_move assignment"/>
799   <link linkend="ecv2_move assignment">Move
800       assignment operator</link>
801 </bridgehead>
802     </para>
803 <programlisting><phrase role="identifier">execution_context</phrase> <phrase role="special">&amp;</phrase> <phrase role="keyword">operator</phrase><phrase role="special">=(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
804 </programlisting>
805     <variablelist>
806       <title></title>
807       <varlistentry>
808         <term>Effects:</term>
809         <listitem>
810           <para>
811             Moves the state of <code><phrase role="identifier">other</phrase></code>
812             to <code><phrase role="special">*</phrase><phrase role="keyword">this</phrase></code>
813             using move semantics.
814           </para>
815         </listitem>
816       </varlistentry>
817       <varlistentry>
818         <term>Throws:</term>
819         <listitem>
820           <para>
821             Nothing.
822           </para>
823         </listitem>
824       </varlistentry>
825     </variablelist>
826     <para>
827       <bridgehead renderas="sect4" id="ecv2_operator_bool_bridgehead">
828   <phrase id="ecv2_operator_bool"/>
829   <link linkend="ecv2_operator_bool">Member function
830       <code>operator bool</code>()</link>
831 </bridgehead>
832     </para>
833 <programlisting><phrase role="keyword">explicit</phrase> <phrase role="keyword">operator</phrase> <phrase role="keyword">bool</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
834 </programlisting>
835     <variablelist>
836       <title></title>
837       <varlistentry>
838         <term>Returns:</term>
839         <listitem>
840           <para>
841             <code><phrase role="keyword">true</phrase></code> if <code><phrase role="special">*</phrase><phrase
842             role="keyword">this</phrase></code> points to a capture record.
843           </para>
844         </listitem>
845       </varlistentry>
846       <varlistentry>
847         <term>Throws:</term>
848         <listitem>
849           <para>
850             Nothing.
851           </para>
852         </listitem>
853       </varlistentry>
854     </variablelist>
855     <para>
856       <bridgehead renderas="sect4" id="ecv2_operator_not_bridgehead">
857   <phrase id="ecv2_operator_not"/>
858   <link linkend="ecv2_operator_not">Member function
859       <code>operator!</code>()</link>
860 </bridgehead>
861     </para>
862 <programlisting><phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">!()</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
863 </programlisting>
864     <variablelist>
865       <title></title>
866       <varlistentry>
867         <term>Returns:</term>
868         <listitem>
869           <para>
870             <code><phrase role="keyword">true</phrase></code> if <code><phrase role="special">*</phrase><phrase
871             role="keyword">this</phrase></code> does not point to a capture record.
872           </para>
873         </listitem>
874       </varlistentry>
875       <varlistentry>
876         <term>Throws:</term>
877         <listitem>
878           <para>
879             Nothing.
880           </para>
881         </listitem>
882       </varlistentry>
883     </variablelist>
884     <para>
885       <bridgehead renderas="sect4" id="ecv2_operator_call_bridgehead">
886   <phrase id="ecv2_operator_call"/>
887   <link linkend="ecv2_operator_call">Member function
888       <code>operator()</code>()</link>
889 </bridgehead>
890     </para>
891 <programlisting><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">tuple</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">Args</phrase> <phrase role="special">...</phrase> <phrase role="special">&gt;,</phrase> <phrase role="identifier">Args</phrase> <phrase role="special">...</phrase> <phrase role="special">&gt;</phrase> <phrase role="keyword">operator</phrase><phrase role="special">()(</phrase> <phrase role="identifier">Args</phrase> <phrase role="special">...</phrase> <phrase role="identifier">args</phrase><phrase role="special">);</phrase> <phrase role="comment">// member of generic execution_context template</phrase>
892
893 <phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">void</phrase> <phrase role="special">&gt;</phrase> <phrase role="keyword">operator</phrase><phrase role="special">()();</phrase> <phrase role="comment">// member of execution_context&lt; void &gt;</phrase>
894 </programlisting>
895     <variablelist>
896       <title></title>
897       <varlistentry>
898         <term>Effects:</term>
899         <listitem>
900           <para>
901             Stores internally the current context data (stack pointer, instruction
902             pointer, and CPU registers) of the current active context and restores
903             the context data from <code><phrase role="special">*</phrase><phrase
904             role="keyword">this</phrase></code>, which implies jumping to <code><phrase
905             role="special">*</phrase><phrase role="keyword">this</phrase></code>'s
906             context. The arguments, <code><phrase role="special">...</phrase> <phrase
907             role="identifier">args</phrase></code>, are passed to the current context
908             to be returned by the most recent call to <code><phrase role="identifier">execution_context</phrase><phrase
909             role="special">::</phrase><phrase role="keyword">operator</phrase><phrase
910             role="special">()</phrase></code> in the same thread.
911           </para>
912         </listitem>
913       </varlistentry>
914       <varlistentry>
915         <term>Returns:</term>
916         <listitem>
917           <para>
918             The tuple of execution_context and returned arguments passed to the most
919             recent call to <code><phrase role="identifier">execution_context</phrase><phrase
920             role="special">::</phrase><phrase role="keyword">operator</phrase><phrase
921             role="special">()</phrase></code>, if any and a execution_context representing
922             the context that has been suspended.
923           </para>
924         </listitem>
925       </varlistentry>
926       <varlistentry>
927         <term>Note:</term>
928         <listitem>
929           <para>
930             The returned execution_context indicates if the suspended context has
931             terminated (return from context-function) via <code><phrase role="keyword">bool</phrase>
932             <phrase role="keyword">operator</phrase><phrase role="special">()</phrase></code>.
933             If the returned execution_context has terminated no data are transferred
934             in the returned tuple.
935           </para>
936         </listitem>
937       </varlistentry>
938     </variablelist>
939     <para>
940       <bridgehead renderas="sect4" id="ecv2_operator_call_ontop_bridgehead">
941   <phrase id="ecv2_operator_call_ontop"/>
942   <link linkend="ecv2_operator_call_ontop">Member
943       function <code>operator()</code>()</link>
944 </bridgehead>
945     </para>
946 <programlisting><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Fn</phrase> <phrase role="special">&gt;</phrase>
947 <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">tuple</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">Args</phrase> <phrase role="special">...</phrase> <phrase role="special">&gt;,</phrase> <phrase role="identifier">Args</phrase> <phrase role="special">...</phrase> <phrase role="special">&gt;</phrase> <phrase role="keyword">operator</phrase><phrase role="special">()(</phrase> <phrase role="identifier">exec_ontop_arg_t</phrase><phrase role="special">,</phrase> <phrase role="identifier">Fn</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">fn</phrase><phrase role="special">,</phrase> <phrase role="identifier">Args</phrase> <phrase role="special">...</phrase> <phrase role="identifier">args</phrase><phrase role="special">);</phrase> <phrase role="comment">// member of generic execution_context</phrase>
948
949 <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Fn</phrase> <phrase role="special">&gt;</phrase>
950 <phrase role="identifier">execution_context</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">void</phrase> <phrase role="special">&gt;</phrase> <phrase role="keyword">operator</phrase><phrase role="special">()(</phrase> <phrase role="identifier">exec_ontop_arg_t</phrase><phrase role="special">,</phrase> <phrase role="identifier">Fn</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">fn</phrase><phrase role="special">);</phrase> <phrase role="comment">// member of execution_context&lt; void &gt;</phrase>
951 </programlisting>
952     <variablelist>
953       <title></title>
954       <varlistentry>
955         <term>Effects:</term>
956         <listitem>
957           <para>
958             Same as <emphasis>execution_context::operator()</emphasis>. Additionally,
959             function <code><phrase role="identifier">fn</phrase></code> is executed
960             in the context of <code><phrase role="special">*</phrase><phrase role="keyword">this</phrase></code>
961             (e.g. the stack frame of <code><phrase role="identifier">fn</phrase></code>
962             is allocated on stack of <code><phrase role="special">*</phrase><phrase
963             role="keyword">this</phrase></code>).
964           </para>
965         </listitem>
966       </varlistentry>
967       <varlistentry>
968         <term>Returns:</term>
969         <listitem>
970           <para>
971             The tuple of execution_context and returned arguments passed to the most
972             recent call to <code><phrase role="identifier">execution_context</phrase><phrase
973             role="special">::</phrase><phrase role="keyword">operator</phrase><phrase
974             role="special">()</phrase></code>, if any and a execution_context representing
975             the context that has been suspended .
976           </para>
977         </listitem>
978       </varlistentry>
979       <varlistentry>
980         <term>Note:</term>
981         <listitem>
982           <para>
983             The tuple of execution_context and returned arguments from <code><phrase
984             role="identifier">fn</phrase></code> are passed as arguments to the context-function
985             of resumed context (if the context is entered the first time) or those
986             arguments are returned from <code><phrase role="identifier">execution_context</phrase><phrase
987             role="special">::</phrase><phrase role="keyword">operator</phrase><phrase
988             role="special">()</phrase></code> within the resumed context.
989           </para>
990         </listitem>
991       </varlistentry>
992       <varlistentry>
993         <term>Note:</term>
994         <listitem>
995           <para>
996             Function <code><phrase role="identifier">fn</phrase></code> needs to
997             return a tuple of arguments (<link linkend="ecv2_ontop">see description</link>).
998           </para>
999         </listitem>
1000       </varlistentry>
1001       <varlistentry>
1002         <term>Note:</term>
1003         <listitem>
1004           <para>
1005             The context calling this function must not be destroyed before the arguments,
1006             that will be returned from <code><phrase role="identifier">fn</phrase></code>,
1007             are preserved at least in the stack frame of the resumed context.
1008           </para>
1009         </listitem>
1010       </varlistentry>
1011       <varlistentry>
1012         <term>Note:</term>
1013         <listitem>
1014           <para>
1015             The returned execution_context indicates if the suspended context has
1016             terminated (return from context-function) via <code><phrase role="keyword">bool</phrase>
1017             <phrase role="keyword">operator</phrase><phrase role="special">()</phrase></code>.
1018             If the returned execution_context has terminated no data are transferred
1019             in the returned tuple.
1020           </para>
1021         </listitem>
1022       </varlistentry>
1023     </variablelist>
1024     <para>
1025       <bridgehead renderas="sect4" id="ecv2_operator_equal_bridgehead">
1026   <phrase id="ecv2_operator_equal"/>
1027   <link linkend="ecv2_operator_equal">Member
1028       function <code>operator==</code>()</link>
1029 </bridgehead>
1030     </para>
1031 <programlisting><phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">==(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1032 </programlisting>
1033     <variablelist>
1034       <title></title>
1035       <varlistentry>
1036         <term>Returns:</term>
1037         <listitem>
1038           <para>
1039             <code><phrase role="keyword">true</phrase></code> if <code><phrase role="special">*</phrase><phrase
1040             role="keyword">this</phrase></code> and <code><phrase role="identifier">other</phrase></code>
1041             represent the same execution context, <code><phrase role="keyword">false</phrase></code>
1042             otherwise.
1043           </para>
1044         </listitem>
1045       </varlistentry>
1046       <varlistentry>
1047         <term>Throws:</term>
1048         <listitem>
1049           <para>
1050             Nothing.
1051           </para>
1052         </listitem>
1053       </varlistentry>
1054     </variablelist>
1055     <para>
1056       <bridgehead renderas="sect4" id="ecv2_operator_notequal_bridgehead">
1057   <phrase id="ecv2_operator_notequal"/>
1058   <link linkend="ecv2_operator_notequal">Member
1059       function <code>operator!=</code>()</link>
1060 </bridgehead>
1061     </para>
1062 <programlisting><phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">!=(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1063 </programlisting>
1064     <variablelist>
1065       <title></title>
1066       <varlistentry>
1067         <term>Returns:</term>
1068         <listitem>
1069           <para>
1070             <code>! (other == * this)</code>
1071           </para>
1072         </listitem>
1073       </varlistentry>
1074       <varlistentry>
1075         <term>Throws:</term>
1076         <listitem>
1077           <para>
1078             Nothing.
1079           </para>
1080         </listitem>
1081       </varlistentry>
1082     </variablelist>
1083     <para>
1084       <bridgehead renderas="sect4" id="ecv2_operator_less_bridgehead">
1085   <phrase id="ecv2_operator_less"/>
1086   <link linkend="ecv2_operator_less">Member function
1087       <code>operator&lt;</code>()</link>
1088 </bridgehead>
1089     </para>
1090 <programlisting><phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">&lt;(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1091 </programlisting>
1092     <variablelist>
1093       <title></title>
1094       <varlistentry>
1095         <term>Returns:</term>
1096         <listitem>
1097           <para>
1098             <code><phrase role="keyword">true</phrase></code> if <code><phrase role="special">*</phrase><phrase
1099             role="keyword">this</phrase> <phrase role="special">!=</phrase> <phrase
1100             role="identifier">other</phrase></code> is true and the implementation-defined
1101             total order of <code><phrase role="identifier">execution_context</phrase></code>
1102             values places <code><phrase role="special">*</phrase><phrase role="keyword">this</phrase></code>
1103             before <code><phrase role="identifier">other</phrase></code>, false otherwise.
1104           </para>
1105         </listitem>
1106       </varlistentry>
1107       <varlistentry>
1108         <term>Throws:</term>
1109         <listitem>
1110           <para>
1111             Nothing.
1112           </para>
1113         </listitem>
1114       </varlistentry>
1115     </variablelist>
1116     <para>
1117       <bridgehead renderas="sect4" id="ecv2_operator_greater_bridgehead">
1118   <phrase id="ecv2_operator_greater"/>
1119   <link linkend="ecv2_operator_greater">Member
1120       function <code>operator&gt;</code>()</link>
1121 </bridgehead>
1122     </para>
1123 <programlisting><phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">&gt;(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1124 </programlisting>
1125     <variablelist>
1126       <title></title>
1127       <varlistentry>
1128         <term>Returns:</term>
1129         <listitem>
1130           <para>
1131             <code><phrase role="identifier">other</phrase> <phrase role="special">&lt;</phrase>
1132             <phrase role="special">*</phrase> <phrase role="keyword">this</phrase></code>
1133           </para>
1134         </listitem>
1135       </varlistentry>
1136       <varlistentry>
1137         <term>Throws:</term>
1138         <listitem>
1139           <para>
1140             Nothing.
1141           </para>
1142         </listitem>
1143       </varlistentry>
1144     </variablelist>
1145     <para>
1146       <bridgehead renderas="sect4" id="ecv2_operator_lesseq_bridgehead">
1147   <phrase id="ecv2_operator_lesseq"/>
1148   <link linkend="ecv2_operator_lesseq">Member
1149       function <code>operator&lt;=</code>()</link>
1150 </bridgehead>
1151     </para>
1152 <programlisting><phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">&lt;=(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1153 </programlisting>
1154     <variablelist>
1155       <title></title>
1156       <varlistentry>
1157         <term>Returns:</term>
1158         <listitem>
1159           <para>
1160             <code><phrase role="special">!</phrase> <phrase role="special">(</phrase><phrase
1161             role="identifier">other</phrase> <phrase role="special">&lt;</phrase>
1162             <phrase role="special">*</phrase> <phrase role="keyword">this</phrase><phrase
1163             role="special">)</phrase></code>
1164           </para>
1165         </listitem>
1166       </varlistentry>
1167       <varlistentry>
1168         <term>Throws:</term>
1169         <listitem>
1170           <para>
1171             Nothing.
1172           </para>
1173         </listitem>
1174       </varlistentry>
1175     </variablelist>
1176     <para>
1177       <bridgehead renderas="sect4" id="ecv2_operator_greatereq_bridgehead">
1178   <phrase id="ecv2_operator_greatereq"/>
1179   <link linkend="ecv2_operator_greatereq">Member
1180       function <code>operator&gt;=</code>()</link>
1181 </bridgehead>
1182     </para>
1183 <programlisting><phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">&gt;=(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1184 </programlisting>
1185     <variablelist>
1186       <title></title>
1187       <varlistentry>
1188         <term>Returns:</term>
1189         <listitem>
1190           <para>
1191             <code><phrase role="special">!</phrase> <phrase role="special">(*</phrase>
1192             <phrase role="keyword">this</phrase> <phrase role="special">&lt;</phrase>
1193             <phrase role="identifier">other</phrase><phrase role="special">)</phrase></code>
1194           </para>
1195         </listitem>
1196       </varlistentry>
1197       <varlistentry>
1198         <term>Throws:</term>
1199         <listitem>
1200           <para>
1201             Nothing.
1202           </para>
1203         </listitem>
1204       </varlistentry>
1205     </variablelist>
1206     <para>
1207       <bridgehead renderas="sect4" id="ecv2__bridgehead">
1208   <phrase id="ecv2_"/>
1209   <link linkend="ecv2_">Non-member function <code>operator&lt;&lt;()</code></link>
1210 </bridgehead>
1211     </para>
1212 <programlisting><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">charT</phrase><phrase role="special">,</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">traitsT</phrase> <phrase role="special">&gt;</phrase>
1213 <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">basic_ostream</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">charT</phrase><phrase role="special">,</phrase> <phrase role="identifier">traitsT</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&amp;</phrase>
1214 <phrase role="keyword">operator</phrase><phrase role="special">&lt;&lt;(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">basic_ostream</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">charT</phrase><phrase role="special">,</phrase> <phrase role="identifier">traitsT</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&amp;</phrase> <phrase role="identifier">os</phrase><phrase role="special">,</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">);</phrase>
1215 </programlisting>
1216     <variablelist>
1217       <title></title>
1218       <varlistentry>
1219         <term>Efects:</term>
1220         <listitem>
1221           <para>
1222             Writes the representation of <code><phrase role="identifier">other</phrase></code>
1223             to stream <code><phrase role="identifier">os</phrase></code>.
1224           </para>
1225         </listitem>
1226       </varlistentry>
1227       <varlistentry>
1228         <term>Returns:</term>
1229         <listitem>
1230           <para>
1231             <code><phrase role="identifier">os</phrase></code>
1232           </para>
1233         </listitem>
1234       </varlistentry>
1235     </variablelist>
1236   </section>
1237   <section id="context.ecv1">
1238     <title><anchor id="ecv1"/><link linkend="context.ecv1">Class execution_context
1239     (version 1)</link></title>
1240     <note>
1241       <para>
1242         This class is only enabled if property <emphasis>segmented-stacks=on</emphasis>
1243         (enables segmented stacks) or compiler flag <emphasis>BOOST_EXECUTION_CONTEXT=1</emphasis>
1244         is specified at b2-commandline.
1245       </para>
1246     </note>
1247     <para>
1248       Class <emphasis>execution_context</emphasis> encapsulates context switching
1249       and manages the associated context' stack (allocation/deallocation).
1250     </para>
1251     <para>
1252       <emphasis>execution_context</emphasis> allocates the context stack (using its
1253       <link linkend="stack"><emphasis>StackAllocator</emphasis></link> argument)
1254       and creates a control structure on top of it. This structure is responsible
1255       for managing context' stack. Instances of <emphasis>execution_context</emphasis>,
1256       associated with a specific context, share the ownership of the control structure.
1257       If the last reference goes out of scope, the control structure is destroyed
1258       and the stack gets deallocated via the <emphasis>StackAllocator</emphasis>.
1259     </para>
1260     <para>
1261       <emphasis>execution_context</emphasis> is copy-constructible, move-constructible,
1262       copy-assignable and move-assignable.
1263     </para>
1264     <para>
1265       <emphasis>execution_context</emphasis> maintains a static (thread-local) pointer,
1266       accessed by <emphasis>execution_context::current()</emphasis>, pointing to
1267       the active context. On each context switch the pointer is updated. The usage
1268       of this global pointer makes the context switch a little bit slower (due access
1269       of thread local storage) but has some advantages. It allows to access the control
1270       structure of the current active context from arbitrary code paths required
1271       in order to support segmented stacks, which require to call certain maintenance
1272       functions (like __splitstack_getcontext() etc.) before each context switch
1273       (each context switch exchanges the stack).
1274     </para>
1275     <para>
1276       <emphasis>execution_context</emphasis> expects a function/functor with signature
1277       <code><phrase role="keyword">void</phrase><phrase role="special">(</phrase><phrase
1278       role="keyword">void</phrase><phrase role="special">*</phrase> <phrase role="identifier">vp</phrase><phrase
1279       role="special">)</phrase></code> (<code><phrase role="identifier">vp</phrase></code>
1280       is the data passed at the first invocation of <link linkend="ecv1_operator_call"> <code>ecv1::operator()()</code></link>).
1281     </para>
1282     <bridgehead renderas="sect3" id="context.ecv1.h0">
1283       <phrase id="context.ecv1.usage_of__emphasis_execution_context__emphasis_"/><link
1284       linkend="context.ecv1.usage_of__emphasis_execution_context__emphasis_">usage
1285       of <emphasis>execution_context</emphasis></link>
1286     </bridgehead>
1287 <programlisting><phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">=</phrase><phrase role="number">35</phrase><phrase role="special">;</phrase>
1288 <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase> <phrase role="identifier">sink</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">::</phrase><phrase role="identifier">current</phrase><phrase role="special">());</phrase>
1289 <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase> <phrase role="identifier">source</phrase><phrase role="special">(</phrase>
1290     <phrase role="special">[</phrase><phrase role="identifier">n</phrase><phrase role="special">,&amp;</phrase><phrase role="identifier">sink</phrase><phrase role="special">](</phrase><phrase role="keyword">void</phrase><phrase role="special">*)</phrase><phrase role="keyword">mutable</phrase><phrase role="special">{</phrase>
1291         <phrase role="keyword">int</phrase> <phrase role="identifier">a</phrase><phrase role="special">=</phrase><phrase role="number">0</phrase><phrase role="special">;</phrase>
1292         <phrase role="keyword">int</phrase> <phrase role="identifier">b</phrase><phrase role="special">=</phrase><phrase role="number">1</phrase><phrase role="special">;</phrase>
1293         <phrase role="keyword">while</phrase><phrase role="special">(</phrase><phrase role="identifier">n</phrase><phrase role="special">--&gt;</phrase><phrase role="number">0</phrase><phrase role="special">){</phrase>
1294             <phrase role="identifier">sink</phrase><phrase role="special">(&amp;</phrase><phrase role="identifier">a</phrase><phrase role="special">);</phrase>
1295             <phrase role="keyword">auto</phrase> <phrase role="identifier">next</phrase><phrase role="special">=</phrase><phrase role="identifier">a</phrase><phrase role="special">+</phrase><phrase role="identifier">b</phrase><phrase role="special">;</phrase>
1296             <phrase role="identifier">a</phrase><phrase role="special">=</phrase><phrase role="identifier">b</phrase><phrase role="special">;</phrase>
1297             <phrase role="identifier">b</phrase><phrase role="special">=</phrase><phrase role="identifier">next</phrase><phrase role="special">;</phrase>
1298         <phrase role="special">}</phrase>
1299     <phrase role="special">});</phrase>
1300 <phrase role="keyword">for</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase><phrase role="special">=</phrase><phrase role="number">0</phrase><phrase role="special">;</phrase><phrase role="identifier">i</phrase><phrase role="special">&lt;</phrase><phrase role="number">10</phrase><phrase role="special">;++</phrase><phrase role="identifier">i</phrase><phrase role="special">){</phrase>
1301     <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase><phrase role="special">&lt;&lt;*(</phrase><phrase role="keyword">int</phrase><phrase role="special">*)</phrase><phrase role="identifier">source</phrase><phrase role="special">()&lt;&lt;</phrase><phrase role="string">&quot; &quot;</phrase><phrase role="special">;</phrase>
1302 <phrase role="special">}</phrase>
1303
1304 <phrase role="identifier">output</phrase><phrase role="special">:</phrase>
1305     <phrase role="number">0</phrase> <phrase role="number">1</phrase> <phrase role="number">1</phrase> <phrase role="number">2</phrase> <phrase role="number">3</phrase> <phrase role="number">5</phrase> <phrase role="number">8</phrase> <phrase role="number">13</phrase> <phrase role="number">21</phrase> <phrase role="number">34</phrase>
1306 </programlisting>
1307     <para>
1308       This simple example demonstrates the basic usage of <emphasis>execution_context</emphasis>.
1309       The context <code><phrase role="identifier">sink</phrase></code>, returned
1310       by <emphasis>execution_context::current()</emphasis>, represents the <emphasis>main</emphasis>-context
1311       (function <emphasis>main()</emphasis> running) and is one of the captured parameters
1312       in the lambda expression. The lambda that calculates the Fibonacci numbers
1313       is executed inside the context represented by <code><phrase role="identifier">source</phrase></code>.
1314       Calculated Fibonacci numbers are transferred between the two context' via expression
1315       <emphasis>sink(&amp;a)</emphasis> (and returned by <emphasis>source()</emphasis>).
1316     </para>
1317     <para>
1318       The locale variables <code><phrase role="identifier">a</phrase></code>, <code><phrase
1319       role="identifier">b</phrase></code> and <code> <phrase role="identifier">next</phrase></code>
1320       remain their values during each context switch (<emphasis>yield(a)</emphasis>).
1321       This is possible because <code><phrase role="identifier">ctx</phrase></code>
1322       owns a stack (exchanged by context switch).
1323     </para>
1324     <bridgehead renderas="sect3" id="context.ecv1.h1">
1325       <phrase id="context.ecv1.inverting_the_control_flow"/><link linkend="context.ecv1.inverting_the_control_flow">inverting
1326       the control flow</link>
1327     </bridgehead>
1328 <programlisting><phrase role="comment">/*
1329  * grammar:
1330  *   P ---&gt; E '\0'
1331  *   E ---&gt; T {('+'|'-') T}
1332  *   T ---&gt; S {('*'|'/') S}
1333  *   S ---&gt; digit | '(' E ')'
1334  */</phrase>
1335 <phrase role="keyword">class</phrase> <phrase role="identifier">Parser</phrase><phrase role="special">{</phrase>
1336     <phrase role="comment">// implementation omitted; see examples directory</phrase>
1337 <phrase role="special">};</phrase>
1338
1339 <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">istringstream</phrase> <phrase role="identifier">is</phrase><phrase role="special">(</phrase><phrase role="string">&quot;1+1&quot;</phrase><phrase role="special">);</phrase>
1340 <phrase role="keyword">bool</phrase> <phrase role="identifier">done</phrase><phrase role="special">=</phrase><phrase role="keyword">false</phrase><phrase role="special">;</phrase>
1341 <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception_ptr</phrase> <phrase role="identifier">except</phrase><phrase role="special">;</phrase>
1342
1343 <phrase role="comment">// create handle to main execution context</phrase>
1344 <phrase role="keyword">auto</phrase> <phrase role="identifier">main_ctx</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">::</phrase><phrase role="identifier">current</phrase><phrase role="special">());</phrase>
1345 <phrase role="comment">// execute parser in new execution context</phrase>
1346 <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase> <phrase role="identifier">source</phrase><phrase role="special">(</phrase>
1347         <phrase role="special">[&amp;</phrase><phrase role="identifier">sink</phrase><phrase role="special">,&amp;</phrase><phrase role="identifier">is</phrase><phrase role="special">,&amp;</phrase><phrase role="identifier">done</phrase><phrase role="special">,&amp;</phrase><phrase role="identifier">except</phrase><phrase role="special">](</phrase><phrase role="keyword">void</phrase><phrase role="special">*){</phrase>
1348         <phrase role="comment">// create parser with callback function</phrase>
1349         <phrase role="identifier">Parser</phrase> <phrase role="identifier">p</phrase><phrase role="special">(</phrase><phrase role="identifier">is</phrase><phrase role="special">,</phrase>
1350                  <phrase role="special">[&amp;</phrase><phrase role="identifier">sink</phrase><phrase role="special">](</phrase><phrase role="keyword">char</phrase> <phrase role="identifier">ch</phrase><phrase role="special">){</phrase>
1351                         <phrase role="comment">// resume main execution context</phrase>
1352                         <phrase role="identifier">sink</phrase><phrase role="special">(&amp;</phrase><phrase role="identifier">ch</phrase><phrase role="special">);</phrase>
1353                 <phrase role="special">});</phrase>
1354             <phrase role="keyword">try</phrase> <phrase role="special">{</phrase>
1355                 <phrase role="comment">// start recursive parsing</phrase>
1356                 <phrase role="identifier">p</phrase><phrase role="special">.</phrase><phrase role="identifier">run</phrase><phrase role="special">();</phrase>
1357             <phrase role="special">}</phrase> <phrase role="keyword">catch</phrase> <phrase role="special">(...)</phrase> <phrase role="special">{</phrase>
1358                 <phrase role="comment">// store other exceptions in exception-pointer</phrase>
1359                 <phrase role="identifier">except</phrase> <phrase role="special">=</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">current_exception</phrase><phrase role="special">();</phrase>
1360             <phrase role="special">}</phrase>
1361             <phrase role="comment">// set termination flag</phrase>
1362             <phrase role="identifier">done</phrase><phrase role="special">=</phrase><phrase role="keyword">true</phrase><phrase role="special">;</phrase>
1363             <phrase role="comment">// resume main execution context</phrase>
1364             <phrase role="identifier">sink</phrase><phrase role="special">();</phrase>
1365         <phrase role="special">});</phrase>
1366
1367 <phrase role="comment">// user-code pulls parsed data from parser</phrase>
1368 <phrase role="comment">// invert control flow</phrase>
1369 <phrase role="keyword">void</phrase><phrase role="special">*</phrase> <phrase role="identifier">vp</phrase> <phrase role="special">=</phrase> <phrase role="identifier">source</phrase><phrase role="special">();</phrase>
1370 <phrase role="keyword">if</phrase> <phrase role="special">(</phrase><phrase role="identifier">except</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
1371     <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">rethrow_exception</phrase><phrase role="special">(</phrase><phrase role="identifier">except</phrase><phrase role="special">);</phrase>
1372 <phrase role="special">}</phrase>
1373 <phrase role="keyword">while</phrase><phrase role="special">(</phrase> <phrase role="special">!</phrase> <phrase role="identifier">done</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
1374     <phrase role="identifier">printf</phrase><phrase role="special">(</phrase><phrase role="string">&quot;Parsed: %c\n&quot;</phrase><phrase role="special">,*</phrase> <phrase role="keyword">static_cast</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">char</phrase><phrase role="special">*&gt;(</phrase><phrase role="identifier">vp</phrase><phrase role="special">));</phrase>
1375     <phrase role="identifier">vp</phrase> <phrase role="special">=</phrase> <phrase role="identifier">source</phrase><phrase role="special">();</phrase>
1376     <phrase role="keyword">if</phrase> <phrase role="special">(</phrase><phrase role="identifier">except</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
1377         <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">rethrow_exception</phrase><phrase role="special">(</phrase><phrase role="identifier">except</phrase><phrase role="special">);</phrase>
1378     <phrase role="special">}</phrase>
1379 <phrase role="special">}</phrase>
1380
1381 <phrase role="identifier">output</phrase><phrase role="special">:</phrase>
1382     <phrase role="identifier">Parsed</phrase><phrase role="special">:</phrase> <phrase role="number">1</phrase>
1383     <phrase role="identifier">Parsed</phrase><phrase role="special">:</phrase> <phrase role="special">+</phrase>
1384     <phrase role="identifier">Parsed</phrase><phrase role="special">:</phrase> <phrase role="number">1</phrase>
1385 </programlisting>
1386     <para>
1387       In this example a recursive descent parser uses a callback to emit a newly
1388       passed symbol. Using <emphasis>execution_context</emphasis> the control flow
1389       can be inverted, e.g. the user-code pulls parsed symbols from the parser -
1390       instead to get pushed from the parser (via callback).
1391     </para>
1392     <para>
1393       The data (character) is transferred between the two <emphasis>execution_context</emphasis>.
1394     </para>
1395     <para>
1396       If the code executed by <emphasis>execution_context</emphasis> emits an exception,
1397       the application is terminated. <emphasis>std::exception_ptr</emphasis> can
1398       be used to transfer exceptions between different execution contexts.
1399     </para>
1400     <bridgehead renderas="sect3" id="context.ecv1.h2">
1401       <phrase id="context.ecv1.stack_unwinding"/><link linkend="context.ecv1.stack_unwinding">stack
1402       unwinding</link>
1403     </bridgehead>
1404     <para>
1405       Sometimes it is necessary to unwind the stack of an unfinished context to destroy
1406       local stack variables so they can release allocated resources (RAII pattern).
1407       The user is responsible for this task.
1408     </para>
1409     <anchor id="ecv1_prealloc"/>
1410     <bridgehead renderas="sect3" id="context.ecv1.h3">
1411       <phrase id="context.ecv1.allocating_control_structures_on_top_of_stack"/><link
1412       linkend="context.ecv1.allocating_control_structures_on_top_of_stack">allocating
1413       control structures on top of stack</link>
1414     </bridgehead>
1415     <para>
1416       Allocating control structures on top of the stack requires to allocated the
1417       <emphasis>stack_context</emphasis> and create the control structure with placement
1418       new before <emphasis>execution_context</emphasis> is created.
1419     </para>
1420     <note>
1421       <para>
1422         The user is responsible for destructing the control structure at the top
1423         of the stack.
1424       </para>
1425     </note>
1426 <programlisting><phrase role="comment">// stack-allocator used for (de-)allocating stack</phrase>
1427 <phrase role="identifier">fixedsize_stack</phrase> <phrase role="identifier">salloc</phrase><phrase role="special">(</phrase> <phrase role="number">4048</phrase><phrase role="special">);</phrase>
1428 <phrase role="comment">// allocate stack space</phrase>
1429 <phrase role="identifier">stack_context</phrase> <phrase role="identifier">sctx</phrase><phrase role="special">(</phrase> <phrase role="identifier">salloc</phrase><phrase role="special">.</phrase><phrase role="identifier">allocate</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
1430 <phrase role="comment">// reserve space for control structure on top of the stack</phrase>
1431 <phrase role="keyword">void</phrase> <phrase role="special">*</phrase> <phrase role="identifier">sp</phrase> <phrase role="special">=</phrase> <phrase role="keyword">static_cast</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">char</phrase> <phrase role="special">*</phrase> <phrase role="special">&gt;(</phrase> <phrase role="identifier">sctx</phrase><phrase role="special">.</phrase><phrase role="identifier">sp</phrase><phrase role="special">)</phrase> <phrase role="special">-</phrase> <phrase role="keyword">sizeof</phrase><phrase role="special">(</phrase> <phrase role="identifier">my_control_structure</phrase><phrase role="special">);</phrase>
1432 <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">size</phrase> <phrase role="special">=</phrase> <phrase role="identifier">sctx</phrase><phrase role="special">.</phrase><phrase role="identifier">size</phrase> <phrase role="special">-</phrase> <phrase role="keyword">sizeof</phrase><phrase role="special">(</phrase> <phrase role="identifier">my_control_structure</phrase><phrase role="special">);</phrase>
1433 <phrase role="comment">// placement new creates control structure on reserved space</phrase>
1434 <phrase role="identifier">my_control_structure</phrase> <phrase role="special">*</phrase> <phrase role="identifier">cs</phrase> <phrase role="special">=</phrase> <phrase role="keyword">new</phrase> <phrase role="special">(</phrase> <phrase role="identifier">sp</phrase><phrase role="special">)</phrase> <phrase role="identifier">my_control_structure</phrase><phrase role="special">(</phrase> <phrase role="identifier">sp</phrase><phrase role="special">,</phrase> <phrase role="identifier">size</phrase><phrase role="special">,</phrase> <phrase role="identifier">sctx</phrase><phrase role="special">,</phrase> <phrase role="identifier">salloc</phrase><phrase role="special">);</phrase>
1435 <phrase role="special">...</phrase>
1436 <phrase role="comment">// destructing the control structure</phrase>
1437 <phrase role="identifier">cs</phrase><phrase role="special">-&gt;~</phrase><phrase role="identifier">my_control_structure</phrase><phrase role="special">();</phrase>
1438 <phrase role="special">...</phrase>
1439 <phrase role="keyword">struct</phrase> <phrase role="identifier">my_control_structure</phrase>  <phrase role="special">{</phrase>
1440     <phrase role="comment">// execution context</phrase>
1441     <phrase role="identifier">execution_context</phrase> <phrase role="identifier">ectx</phrase><phrase role="special">;</phrase>
1442
1443     <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">StackAllocator</phrase> <phrase role="special">&gt;</phrase>
1444     <phrase role="identifier">my_control_structure</phrase><phrase role="special">(</phrase> <phrase role="keyword">void</phrase> <phrase role="special">*</phrase> <phrase role="identifier">sp</phrase><phrase role="special">,</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">size</phrase><phrase role="special">,</phrase> <phrase role="identifier">stack_context</phrase> <phrase role="identifier">sctx</phrase><phrase role="special">,</phrase> <phrase role="identifier">StackAllocator</phrase> <phrase role="identifier">salloc</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase>
1445         <phrase role="comment">// create execution context</phrase>
1446         <phrase role="identifier">ectx</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">allocator_arg</phrase><phrase role="special">,</phrase> <phrase role="identifier">preallocated</phrase><phrase role="special">(</phrase> <phrase role="identifier">sp</phrase><phrase role="special">,</phrase> <phrase role="identifier">size</phrase><phrase role="special">,</phrase> <phrase role="identifier">sctx</phrase><phrase role="special">),</phrase> <phrase role="identifier">salloc</phrase><phrase role="special">,</phrase> <phrase role="identifier">entry_func</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
1447     <phrase role="special">}</phrase>
1448     <phrase role="special">...</phrase>
1449 <phrase role="special">};</phrase>
1450 </programlisting>
1451     <bridgehead renderas="sect3" id="context.ecv1.h4">
1452       <phrase id="context.ecv1.exception_handling"/><link linkend="context.ecv1.exception_handling">exception
1453       handling</link>
1454     </bridgehead>
1455     <para>
1456       If the function executed inside a <emphasis>execution_context</emphasis> emits
1457       ans exception, the application is terminated by calling <emphasis>std::terminate()</emphasis>.
1458       <emphasis>std::exception_ptr</emphasis> can be used to transfer exceptions
1459       between different execution contexts.
1460     </para>
1461     <important>
1462       <para>
1463         Do not jump from inside a catch block and then re-throw the exception in
1464         another execution context.
1465       </para>
1466     </important>
1467     <bridgehead renderas="sect3" id="context.ecv1.h5">
1468       <phrase id="context.ecv1.parameter_passing"/><link linkend="context.ecv1.parameter_passing">parameter
1469       passing</link>
1470     </bridgehead>
1471     <para>
1472       The void pointer argument passed to <emphasis>execution_context::operator()</emphasis>,
1473       in one context, is passed as the last argument of the <emphasis>context-function</emphasis>
1474       if the context is started for the first time. In all following invocations
1475       of <emphasis>execution_context::operator()</emphasis> the void pointer passed
1476       to <emphasis>execution_context::operator()</emphasis>, in one context, is returned
1477       by <emphasis>execution_context::operator()</emphasis> in the other context.
1478     </para>
1479 <programlisting><phrase role="keyword">class</phrase> <phrase role="identifier">X</phrase> <phrase role="special">{</phrase>
1480 <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
1481     <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception_ptr</phrase> <phrase role="identifier">excptr_</phrase><phrase role="special">;</phrase>
1482     <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase> <phrase role="identifier">caller_</phrase><phrase role="special">;</phrase>
1483     <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase> <phrase role="identifier">callee_</phrase><phrase role="special">;</phrase>
1484
1485 <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
1486     <phrase role="identifier">X</phrase><phrase role="special">()</phrase> <phrase role="special">:</phrase>
1487         <phrase role="identifier">excptr_</phrase><phrase role="special">(),</phrase>
1488         <phrase role="identifier">caller_</phrase><phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">context</phrase><phrase role="special">::</phrase><phrase role="identifier">execution_context</phrase><phrase role="special">::</phrase><phrase role="identifier">current</phrase><phrase role="special">()</phrase> <phrase role="special">),</phrase>
1489         <phrase role="identifier">callee_</phrase><phrase role="special">(</phrase> <phrase role="special">[=]</phrase> <phrase role="special">(</phrase><phrase role="keyword">void</phrase> <phrase role="special">*</phrase> <phrase role="identifier">vp</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
1490                     <phrase role="keyword">try</phrase> <phrase role="special">{</phrase>
1491                         <phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="special">*</phrase> <phrase role="keyword">static_cast</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">*</phrase> <phrase role="special">&gt;(</phrase> <phrase role="identifier">vp</phrase><phrase role="special">);</phrase>
1492                         <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="identifier">str</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">lexical_cast</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">i</phrase><phrase role="special">);</phrase>
1493                         <phrase role="identifier">caller_</phrase><phrase role="special">(</phrase> <phrase role="special">&amp;</phrase> <phrase role="identifier">str</phrase><phrase role="special">);</phrase>
1494                     <phrase role="special">}</phrase> <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">bad_cast</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;)</phrase> <phrase role="special">{</phrase>
1495                         <phrase role="identifier">excptr_</phrase><phrase role="special">=</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">current_exception</phrase><phrase role="special">();</phrase>
1496                     <phrase role="special">}</phrase>
1497                  <phrase role="special">})</phrase>
1498     <phrase role="special">{}</phrase>
1499
1500     <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">operator</phrase><phrase role="special">()(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
1501         <phrase role="keyword">void</phrase> <phrase role="special">*</phrase> <phrase role="identifier">ret</phrase> <phrase role="special">=</phrase> <phrase role="identifier">callee_</phrase><phrase role="special">(</phrase> <phrase role="special">&amp;</phrase> <phrase role="identifier">i</phrase><phrase role="special">);</phrase>
1502         <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">excptr_</phrase><phrase role="special">){</phrase>
1503             <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">rethrow_exception</phrase><phrase role="special">(</phrase><phrase role="identifier">excptr_</phrase><phrase role="special">);</phrase>
1504         <phrase role="special">}</phrase>
1505         <phrase role="keyword">return</phrase> <phrase role="special">*</phrase> <phrase role="keyword">static_cast</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="special">*</phrase> <phrase role="special">&gt;(</phrase> <phrase role="identifier">ret</phrase><phrase role="special">);</phrase>
1506     <phrase role="special">}</phrase>
1507 <phrase role="special">};</phrase>
1508
1509 <phrase role="identifier">X</phrase> <phrase role="identifier">x</phrase><phrase role="special">;</phrase>
1510 <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">x</phrase><phrase role="special">(</phrase> <phrase role="number">7</phrase><phrase role="special">)</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
1511
1512 <phrase role="identifier">output</phrase><phrase role="special">:</phrase>
1513     <phrase role="number">7</phrase>
1514 </programlisting>
1515     <bridgehead renderas="sect3" id="context.ecv1.h6">
1516       <phrase id="context.ecv1.class__code__phrase_role__identifier__execution_context__phrase___code_"/><link
1517       linkend="context.ecv1.class__code__phrase_role__identifier__execution_context__phrase___code_">Class
1518       <code><phrase role="identifier">execution_context</phrase></code></link>
1519     </bridgehead>
1520 <programlisting><phrase role="keyword">class</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="special">{</phrase>
1521 <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
1522     <phrase role="keyword">static</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="identifier">current</phrase><phrase role="special">()</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1523
1524     <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Fn</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="special">...</phrase> <phrase role="identifier">Args</phrase> <phrase role="special">&gt;</phrase>
1525     <phrase role="identifier">execution_context</phrase><phrase role="special">(</phrase> <phrase role="identifier">Fn</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">fn</phrase><phrase role="special">,</phrase> <phrase role="identifier">Args</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="special">...</phrase> <phrase role="identifier">args</phrase><phrase role="special">);</phrase>
1526
1527     <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">StackAlloc</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Fn</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="special">...</phrase> <phrase role="identifier">Args</phrase> <phrase role="special">&gt;</phrase>
1528     <phrase role="identifier">execution_context</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">allocator_arg_t</phrase><phrase role="special">,</phrase> <phrase role="identifier">StackAlloc</phrase> <phrase role="identifier">salloc</phrase><phrase role="special">,</phrase> <phrase role="identifier">Fn</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">fn</phrase><phrase role="special">,</phrase> <phrase role="identifier">Args</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="special">...</phrase> <phrase role="identifier">args</phrase><phrase role="special">);</phrase>
1529
1530     <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">StackAlloc</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Fn</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="special">...</phrase> <phrase role="identifier">Args</phrase> <phrase role="special">&gt;</phrase>
1531     <phrase role="identifier">execution_context</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">allocator_arg_t</phrase><phrase role="special">,</phrase> <phrase role="identifier">preallocated</phrase> <phrase role="identifier">palloc</phrase><phrase role="special">,</phrase> <phrase role="identifier">StackAlloc</phrase> <phrase role="identifier">salloc</phrase><phrase role="special">,</phrase> <phrase role="identifier">Fn</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">fn</phrase><phrase role="special">,</phrase> <phrase role="identifier">Args</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="special">...</phrase> <phrase role="identifier">args</phrase><phrase role="special">);</phrase>
1532
1533     <phrase role="identifier">execution_context</phrase><phrase role="special">(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1534     <phrase role="identifier">execution_context</phrase><phrase role="special">(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1535
1536     <phrase role="identifier">execution_context</phrase> <phrase role="special">&amp;</phrase> <phrase role="keyword">operator</phrase><phrase role="special">=(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1537     <phrase role="identifier">execution_context</phrase> <phrase role="special">&amp;</phrase> <phrase role="keyword">operator</phrase><phrase role="special">=(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1538
1539     <phrase role="keyword">explicit</phrase> <phrase role="keyword">operator</phrase> <phrase role="keyword">bool</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1540     <phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">!()</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1541
1542     <phrase role="keyword">void</phrase> <phrase role="special">*</phrase> <phrase role="keyword">operator</phrase><phrase role="special">()(</phrase> <phrase role="keyword">void</phrase> <phrase role="special">*</phrase> <phrase role="identifier">vp</phrase> <phrase role="special">=</phrase> <phrase role="keyword">nullptr</phrase><phrase role="special">);</phrase>
1543
1544     <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Fn</phrase> <phrase role="special">&gt;</phrase>
1545     <phrase role="keyword">void</phrase> <phrase role="special">*</phrase> <phrase role="keyword">operator</phrase><phrase role="special">()(</phrase> <phrase role="identifier">exec_ontop_arg_t</phrase><phrase role="special">,</phrase> <phrase role="identifier">Fn</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">fn</phrase><phrase role="special">,</phrase> <phrase role="keyword">void</phrase> <phrase role="special">*</phrase> <phrase role="identifier">vp</phrase> <phrase role="special">=</phrase> <phrase role="keyword">nullptr</phrase><phrase role="special">);</phrase>
1546
1547     <phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">==(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1548
1549     <phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">!=(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1550
1551     <phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">&lt;(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1552
1553     <phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">&gt;(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1554
1555     <phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">&lt;=(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1556
1557     <phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">&gt;=(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1558
1559     <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">charT</phrase><phrase role="special">,</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">traitsT</phrase> <phrase role="special">&gt;</phrase>
1560     <phrase role="keyword">friend</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">basic_ostream</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">charT</phrase><phrase role="special">,</phrase> <phrase role="identifier">traitsT</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&amp;</phrase>
1561     <phrase role="keyword">operator</phrase><phrase role="special">&lt;&lt;(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">basic_ostream</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">charT</phrase><phrase role="special">,</phrase> <phrase role="identifier">traitsT</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&amp;</phrase> <phrase role="identifier">os</phrase><phrase role="special">,</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">);</phrase>
1562 <phrase role="special">};</phrase>
1563 </programlisting>
1564     <para>
1565       <bridgehead renderas="sect4" id="ecv1_current_bridgehead">
1566   <phrase id="ecv1_current"/>
1567   <link linkend="ecv1_current">Static member function <code>current</code>()</link>
1568 </bridgehead>
1569     </para>
1570 <programlisting><phrase role="keyword">static</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="identifier">current</phrase><phrase role="special">()</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1571 </programlisting>
1572     <variablelist>
1573       <title></title>
1574       <varlistentry>
1575         <term>Returns:</term>
1576         <listitem>
1577           <para>
1578             Returns an instance of excution_context pointing to the active execution
1579             context.
1580           </para>
1581         </listitem>
1582       </varlistentry>
1583       <varlistentry>
1584         <term>Throws:</term>
1585         <listitem>
1586           <para>
1587             Nothing.
1588           </para>
1589         </listitem>
1590       </varlistentry>
1591     </variablelist>
1592     <para>
1593       <bridgehead renderas="sect4" id="ecv1_constructor_bridgehead">
1594   <phrase id="ecv1_constructor"/>
1595   <link linkend="ecv1_constructor">Constructor</link>
1596 </bridgehead>
1597     </para>
1598 <programlisting><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Fn</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="special">...</phrase> <phrase role="identifier">Args</phrase> <phrase role="special">&gt;</phrase>
1599 <phrase role="identifier">execution_context</phrase><phrase role="special">(</phrase> <phrase role="identifier">Fn</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">fn</phrase><phrase role="special">,</phrase> <phrase role="identifier">Args</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="special">...</phrase> <phrase role="identifier">args</phrase><phrase role="special">);</phrase>
1600
1601 <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">StackAlloc</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Fn</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="special">...</phrase> <phrase role="identifier">Args</phrase> <phrase role="special">&gt;</phrase>
1602 <phrase role="identifier">execution_context</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">allocator_arg_t</phrase><phrase role="special">,</phrase> <phrase role="identifier">StackAlloc</phrase> <phrase role="identifier">salloc</phrase><phrase role="special">,</phrase> <phrase role="identifier">Fn</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">fn</phrase><phrase role="special">,</phrase> <phrase role="identifier">Args</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="special">...</phrase> <phrase role="identifier">args</phrase><phrase role="special">);</phrase>
1603
1604 <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">StackAlloc</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Fn</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="special">...</phrase> <phrase role="identifier">Args</phrase> <phrase role="special">&gt;</phrase>
1605 <phrase role="identifier">execution_context</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">allocator_arg_t</phrase><phrase role="special">,</phrase> <phrase role="identifier">preallocated</phrase> <phrase role="identifier">palloc</phrase><phrase role="special">,</phrase> <phrase role="identifier">StackAlloc</phrase> <phrase role="identifier">salloc</phrase><phrase role="special">,</phrase> <phrase role="identifier">Fn</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">fn</phrase><phrase role="special">,</phrase> <phrase role="identifier">Args</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="special">...</phrase> <phrase role="identifier">args</phrase><phrase role="special">);</phrase>
1606 </programlisting>
1607     <variablelist>
1608       <title></title>
1609       <varlistentry>
1610         <term>Effects:</term>
1611         <listitem>
1612           <para>
1613             Creates a new execution context and prepares the context to execute
1614             <code><phrase role="identifier">fn</phrase></code>. <code><phrase role="identifier">fixedsize_stack</phrase></code>
1615             is used as default stack allocator (stack size == fixedsize_stack::traits::default_size()).
1616             The constructor with argument type <code><phrase role="identifier">preallocated</phrase></code>,
1617             is used to create a user defined data <link linkend="ecv1_prealloc">(for
1618             instance additional control structures)</link> on top of the stack.
1619           </para>
1620         </listitem>
1621       </varlistentry>
1622     </variablelist>
1623     <para>
1624       <bridgehead renderas="sect4" id="ecv1_copy constructor_bridgehead">
1625   <phrase id="ecv1_copy constructor"/>
1626   <link linkend="ecv1_copy constructor">Copy
1627       constructor</link>
1628 </bridgehead>
1629     </para>
1630 <programlisting><phrase role="identifier">execution_context</phrase><phrase role="special">(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1631 </programlisting>
1632     <variablelist>
1633       <title></title>
1634       <varlistentry>
1635         <term>Effects:</term>
1636         <listitem>
1637           <para>
1638             Copies <code><phrase role="identifier">other</phrase></code>, e.g. underlying
1639             control structure is shared with <code><phrase role="special">*</phrase><phrase
1640             role="keyword">this</phrase></code>.
1641           </para>
1642         </listitem>
1643       </varlistentry>
1644       <varlistentry>
1645         <term>Throws:</term>
1646         <listitem>
1647           <para>
1648             Nothing.
1649           </para>
1650         </listitem>
1651       </varlistentry>
1652     </variablelist>
1653     <para>
1654       <bridgehead renderas="sect4" id="ecv1_move constructor_bridgehead">
1655   <phrase id="ecv1_move constructor"/>
1656   <link linkend="ecv1_move constructor">Move
1657       constructor</link>
1658 </bridgehead>
1659     </para>
1660 <programlisting><phrase role="identifier">execution_context</phrase><phrase role="special">(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1661 </programlisting>
1662     <variablelist>
1663       <title></title>
1664       <varlistentry>
1665         <term>Effects:</term>
1666         <listitem>
1667           <para>
1668             Moves underlying control structure to <code><phrase role="special">*</phrase><phrase
1669             role="keyword">this</phrase></code>.
1670           </para>
1671         </listitem>
1672       </varlistentry>
1673       <varlistentry>
1674         <term>Throws:</term>
1675         <listitem>
1676           <para>
1677             Nothing.
1678           </para>
1679         </listitem>
1680       </varlistentry>
1681     </variablelist>
1682     <para>
1683       <bridgehead renderas="sect4" id="ecv1_copy assignment_bridgehead">
1684   <phrase id="ecv1_copy assignment"/>
1685   <link linkend="ecv1_copy assignment">Copy
1686       assignment operator</link>
1687 </bridgehead>
1688     </para>
1689 <programlisting><phrase role="identifier">execution_context</phrase> <phrase role="special">&amp;</phrase> <phrase role="keyword">operator</phrase><phrase role="special">=(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1690 </programlisting>
1691     <variablelist>
1692       <title></title>
1693       <varlistentry>
1694         <term>Effects:</term>
1695         <listitem>
1696           <para>
1697             Copies the state of <code><phrase role="identifier">other</phrase></code>
1698             to <code><phrase role="special">*</phrase><phrase role="keyword">this</phrase></code>,
1699             control structure is shared.
1700           </para>
1701         </listitem>
1702       </varlistentry>
1703       <varlistentry>
1704         <term>Throws:</term>
1705         <listitem>
1706           <para>
1707             Nothing.
1708           </para>
1709         </listitem>
1710       </varlistentry>
1711     </variablelist>
1712     <para>
1713       <bridgehead renderas="sect4" id="ecv1_move assignment_bridgehead">
1714   <phrase id="ecv1_move assignment"/>
1715   <link linkend="ecv1_move assignment">Move
1716       assignment operator</link>
1717 </bridgehead>
1718     </para>
1719 <programlisting><phrase role="identifier">execution_context</phrase> <phrase role="special">&amp;</phrase> <phrase role="keyword">operator</phrase><phrase role="special">=(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1720 </programlisting>
1721     <variablelist>
1722       <title></title>
1723       <varlistentry>
1724         <term>Effects:</term>
1725         <listitem>
1726           <para>
1727             Moves the control structure of <code><phrase role="identifier">other</phrase></code>
1728             to <code><phrase role="special">*</phrase><phrase role="keyword">this</phrase></code>
1729             using move semantics.
1730           </para>
1731         </listitem>
1732       </varlistentry>
1733       <varlistentry>
1734         <term>Throws:</term>
1735         <listitem>
1736           <para>
1737             Nothing.
1738           </para>
1739         </listitem>
1740       </varlistentry>
1741     </variablelist>
1742     <para>
1743       <bridgehead renderas="sect4" id="ecv1_operator_bool_bridgehead">
1744   <phrase id="ecv1_operator_bool"/>
1745   <link linkend="ecv1_operator_bool">Member function
1746       <code>operator bool</code>()</link>
1747 </bridgehead>
1748     </para>
1749 <programlisting><phrase role="keyword">explicit</phrase> <phrase role="keyword">operator</phrase> <phrase role="keyword">bool</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1750 </programlisting>
1751     <variablelist>
1752       <title></title>
1753       <varlistentry>
1754         <term>Returns:</term>
1755         <listitem>
1756           <para>
1757             <code><phrase role="keyword">true</phrase></code> if <code><phrase role="special">*</phrase><phrase
1758             role="keyword">this</phrase></code> points to a control structure.
1759           </para>
1760         </listitem>
1761       </varlistentry>
1762       <varlistentry>
1763         <term>Throws:</term>
1764         <listitem>
1765           <para>
1766             Nothing.
1767           </para>
1768         </listitem>
1769       </varlistentry>
1770     </variablelist>
1771     <para>
1772       <bridgehead renderas="sect4" id="ecv1_operator_not_bridgehead">
1773   <phrase id="ecv1_operator_not"/>
1774   <link linkend="ecv1_operator_not">Member function
1775       <code>operator!</code>()</link>
1776 </bridgehead>
1777     </para>
1778 <programlisting><phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">!()</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1779 </programlisting>
1780     <variablelist>
1781       <title></title>
1782       <varlistentry>
1783         <term>Returns:</term>
1784         <listitem>
1785           <para>
1786             <code><phrase role="keyword">true</phrase></code> if <code><phrase role="special">*</phrase><phrase
1787             role="keyword">this</phrase></code> does not point to a control structure.
1788           </para>
1789         </listitem>
1790       </varlistentry>
1791       <varlistentry>
1792         <term>Throws:</term>
1793         <listitem>
1794           <para>
1795             Nothing.
1796           </para>
1797         </listitem>
1798       </varlistentry>
1799     </variablelist>
1800     <para>
1801       <bridgehead renderas="sect4" id="ecv1_operator_call_bridgehead">
1802   <phrase id="ecv1_operator_call"/>
1803   <link linkend="ecv1_operator_call">Member function
1804       <code>operator()</code>()</link>
1805 </bridgehead>
1806     </para>
1807 <programlisting><phrase role="keyword">void</phrase> <phrase role="special">*</phrase> <phrase role="keyword">operator</phrase><phrase role="special">()(</phrase> <phrase role="keyword">void</phrase> <phrase role="special">*</phrase> <phrase role="identifier">vp</phrase> <phrase role="special">=</phrase> <phrase role="keyword">nullptr</phrase><phrase role="special">)</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1808 </programlisting>
1809     <variablelist>
1810       <title></title>
1811       <varlistentry>
1812         <term>Effects:</term>
1813         <listitem>
1814           <para>
1815             Stores internally the current context data (stack pointer, instruction
1816             pointer, and CPU registers) of the current active context and restores
1817             the context data from <code><phrase role="special">*</phrase><phrase
1818             role="keyword">this</phrase></code>, which implies jumping to <code><phrase
1819             role="special">*</phrase><phrase role="keyword">this</phrase></code>'s
1820             context. The void pointer argument, <code><phrase role="identifier">vp</phrase></code>,
1821             is passed to the current context to be returned by the most recent call
1822             to <code><phrase role="identifier">execution_context</phrase><phrase
1823             role="special">::</phrase><phrase role="keyword">operator</phrase><phrase
1824             role="special">()</phrase></code> in the same thread. <code><phrase role="identifier">fn</phrase></code>
1825             is executed with arguments <code><phrase role="identifier">args</phrase></code>
1826             on top of the stack of <code><phrase role="keyword">this</phrase></code>.
1827           </para>
1828         </listitem>
1829       </varlistentry>
1830       <varlistentry>
1831         <term>Note:</term>
1832         <listitem>
1833           <para>
1834             The behaviour is undefined if <code><phrase role="keyword">operator</phrase><phrase
1835             role="special">()()</phrase></code> is called while <emphasis>execution_context::current()</emphasis>
1836             returns <code><phrase role="special">*</phrase><phrase role="keyword">this</phrase></code>
1837             (e.g. resuming an already running context). If the top-level context
1838             function returns, <code><phrase role="identifier">std</phrase><phrase
1839             role="special">::</phrase><phrase role="identifier">exit</phrase><phrase
1840             role="special">()</phrase></code> is called.
1841           </para>
1842         </listitem>
1843       </varlistentry>
1844       <varlistentry>
1845         <term>Returns:</term>
1846         <listitem>
1847           <para>
1848             The void pointer argument passed to the most recent call to <emphasis>execution_context::operator()</emphasis>,
1849             if any.
1850           </para>
1851         </listitem>
1852       </varlistentry>
1853     </variablelist>
1854     <para>
1855       <bridgehead renderas="sect4" id="ecv1_operator_call_ontop_bridgehead">
1856   <phrase id="ecv1_operator_call_ontop"/>
1857   <link linkend="ecv1_operator_call_ontop">Member
1858       function <code>operator(exec_ontop_arg_t)</code>()</link>
1859 </bridgehead>
1860     </para>
1861 <programlisting><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Fn</phrase> <phrase role="special">&gt;</phrase>
1862 <phrase role="keyword">void</phrase> <phrase role="special">*</phrase> <phrase role="keyword">operator</phrase><phrase role="special">()(</phrase> <phrase role="identifier">exec_ontop_arg_t</phrase><phrase role="special">,</phrase> <phrase role="identifier">Fn</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">fn</phrase><phrase role="special">,</phrase> <phrase role="keyword">void</phrase> <phrase role="special">*</phrase> <phrase role="identifier">vp</phrase> <phrase role="special">=</phrase> <phrase role="keyword">nullptr</phrase><phrase role="special">);</phrase>
1863 </programlisting>
1864     <variablelist>
1865       <title></title>
1866       <varlistentry>
1867         <term>Effects:</term>
1868         <listitem>
1869           <para>
1870             Same as <emphasis>execution_context::operator()</emphasis>. Additionally,
1871             function <code><phrase role="identifier">fn</phrase></code> is executed
1872             with arguments <code><phrase role="identifier">vp</phrase></code> in
1873             the context of <code><phrase role="special">*</phrase><phrase role="keyword">this</phrase></code>
1874             (e.g. the stack frame of <code><phrase role="identifier">fn</phrase></code>
1875             is allocated on stack of <code><phrase role="special">*</phrase><phrase
1876             role="keyword">this</phrase></code>).
1877           </para>
1878         </listitem>
1879       </varlistentry>
1880       <varlistentry>
1881         <term>Returns:</term>
1882         <listitem>
1883           <para>
1884             The void pointer argument passed to the most recent call to <emphasis>execution_context::operator()</emphasis>,
1885             if any.
1886           </para>
1887         </listitem>
1888       </varlistentry>
1889     </variablelist>
1890     <para>
1891       <bridgehead renderas="sect4" id="ecv1_operator_equal_bridgehead">
1892   <phrase id="ecv1_operator_equal"/>
1893   <link linkend="ecv1_operator_equal">Member
1894       function <code>operator==</code>()</link>
1895 </bridgehead>
1896     </para>
1897 <programlisting><phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">==(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1898 </programlisting>
1899     <variablelist>
1900       <title></title>
1901       <varlistentry>
1902         <term>Returns:</term>
1903         <listitem>
1904           <para>
1905             <code><phrase role="keyword">true</phrase></code> if <code><phrase role="special">*</phrase><phrase
1906             role="keyword">this</phrase></code> and <code><phrase role="identifier">other</phrase></code>
1907             represent the same execution context, <code><phrase role="keyword">false</phrase></code>
1908             otherwise.
1909           </para>
1910         </listitem>
1911       </varlistentry>
1912       <varlistentry>
1913         <term>Throws:</term>
1914         <listitem>
1915           <para>
1916             Nothing.
1917           </para>
1918         </listitem>
1919       </varlistentry>
1920     </variablelist>
1921     <para>
1922       <bridgehead renderas="sect4" id="ecv1_operator_notequal_bridgehead">
1923   <phrase id="ecv1_operator_notequal"/>
1924   <link linkend="ecv1_operator_notequal">Member
1925       function <code>operator!=</code>()</link>
1926 </bridgehead>
1927     </para>
1928 <programlisting><phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">!=(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1929 </programlisting>
1930     <variablelist>
1931       <title></title>
1932       <varlistentry>
1933         <term>Returns:</term>
1934         <listitem>
1935           <para>
1936             <code>! (other == * this)</code>
1937           </para>
1938         </listitem>
1939       </varlistentry>
1940       <varlistentry>
1941         <term>Throws:</term>
1942         <listitem>
1943           <para>
1944             Nothing.
1945           </para>
1946         </listitem>
1947       </varlistentry>
1948     </variablelist>
1949     <para>
1950       <bridgehead renderas="sect4" id="ecv1_operator_less_bridgehead">
1951   <phrase id="ecv1_operator_less"/>
1952   <link linkend="ecv1_operator_less">Member function
1953       <code>operator&lt;</code>()</link>
1954 </bridgehead>
1955     </para>
1956 <programlisting><phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">&lt;(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1957 </programlisting>
1958     <variablelist>
1959       <title></title>
1960       <varlistentry>
1961         <term>Returns:</term>
1962         <listitem>
1963           <para>
1964             <code><phrase role="keyword">true</phrase></code> if <code><phrase role="special">*</phrase><phrase
1965             role="keyword">this</phrase> <phrase role="special">!=</phrase> <phrase
1966             role="identifier">other</phrase></code> is true and the implementation-defined
1967             total order of <code><phrase role="identifier">execution_context</phrase></code>
1968             values places <code><phrase role="special">*</phrase><phrase role="keyword">this</phrase></code>
1969             before <code><phrase role="identifier">other</phrase></code>, false otherwise.
1970           </para>
1971         </listitem>
1972       </varlistentry>
1973       <varlistentry>
1974         <term>Throws:</term>
1975         <listitem>
1976           <para>
1977             Nothing.
1978           </para>
1979         </listitem>
1980       </varlistentry>
1981     </variablelist>
1982     <para>
1983       <bridgehead renderas="sect4" id="ecv1_operator_greater_bridgehead">
1984   <phrase id="ecv1_operator_greater"/>
1985   <link linkend="ecv1_operator_greater">Member
1986       function <code>operator&gt;</code>()</link>
1987 </bridgehead>
1988     </para>
1989 <programlisting><phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">&gt;(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
1990 </programlisting>
1991     <variablelist>
1992       <title></title>
1993       <varlistentry>
1994         <term>Returns:</term>
1995         <listitem>
1996           <para>
1997             <code><phrase role="identifier">other</phrase> <phrase role="special">&lt;</phrase>
1998             <phrase role="special">*</phrase> <phrase role="keyword">this</phrase></code>
1999           </para>
2000         </listitem>
2001       </varlistentry>
2002       <varlistentry>
2003         <term>Throws:</term>
2004         <listitem>
2005           <para>
2006             Nothing.
2007           </para>
2008         </listitem>
2009       </varlistentry>
2010     </variablelist>
2011     <para>
2012       <bridgehead renderas="sect4" id="ecv1_operator_lesseq_bridgehead">
2013   <phrase id="ecv1_operator_lesseq"/>
2014   <link linkend="ecv1_operator_lesseq">Member
2015       function <code>operator&lt;=</code>()</link>
2016 </bridgehead>
2017     </para>
2018 <programlisting><phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">&lt;=(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
2019 </programlisting>
2020     <variablelist>
2021       <title></title>
2022       <varlistentry>
2023         <term>Returns:</term>
2024         <listitem>
2025           <para>
2026             <code><phrase role="special">!</phrase> <phrase role="special">(</phrase><phrase
2027             role="identifier">other</phrase> <phrase role="special">&lt;</phrase>
2028             <phrase role="special">*</phrase> <phrase role="keyword">this</phrase><phrase
2029             role="special">)</phrase></code>
2030           </para>
2031         </listitem>
2032       </varlistentry>
2033       <varlistentry>
2034         <term>Throws:</term>
2035         <listitem>
2036           <para>
2037             Nothing.
2038           </para>
2039         </listitem>
2040       </varlistentry>
2041     </variablelist>
2042     <para>
2043       <bridgehead renderas="sect4" id="ecv1_operator_greatereq_bridgehead">
2044   <phrase id="ecv1_operator_greatereq"/>
2045   <link linkend="ecv1_operator_greatereq">Member
2046       function <code>operator&gt;=</code>()</link>
2047 </bridgehead>
2048     </para>
2049 <programlisting><phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">&gt;=(</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
2050 </programlisting>
2051     <variablelist>
2052       <title></title>
2053       <varlistentry>
2054         <term>Returns:</term>
2055         <listitem>
2056           <para>
2057             <code><phrase role="special">!</phrase> <phrase role="special">(*</phrase>
2058             <phrase role="keyword">this</phrase> <phrase role="special">&lt;</phrase>
2059             <phrase role="identifier">other</phrase><phrase role="special">)</phrase></code>
2060           </para>
2061         </listitem>
2062       </varlistentry>
2063       <varlistentry>
2064         <term>Throws:</term>
2065         <listitem>
2066           <para>
2067             Nothing.
2068           </para>
2069         </listitem>
2070       </varlistentry>
2071     </variablelist>
2072     <para>
2073       <bridgehead renderas="sect4" id="ecv1__bridgehead">
2074   <phrase id="ecv1_"/>
2075   <link linkend="ecv1_">Non-member function <code>operator&lt;&lt;()</code></link>
2076 </bridgehead>
2077     </para>
2078 <programlisting><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">charT</phrase><phrase role="special">,</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">traitsT</phrase> <phrase role="special">&gt;</phrase>
2079 <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">basic_ostream</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">charT</phrase><phrase role="special">,</phrase> <phrase role="identifier">traitsT</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&amp;</phrase>
2080 <phrase role="keyword">operator</phrase><phrase role="special">&lt;&lt;(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">basic_ostream</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">charT</phrase><phrase role="special">,</phrase> <phrase role="identifier">traitsT</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&amp;</phrase> <phrase role="identifier">os</phrase><phrase role="special">,</phrase> <phrase role="identifier">execution_context</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">);</phrase>
2081 </programlisting>
2082     <variablelist>
2083       <title></title>
2084       <varlistentry>
2085         <term>Efects:</term>
2086         <listitem>
2087           <para>
2088             Writes the representation of <code><phrase role="identifier">other</phrase></code>
2089             to stream <code><phrase role="identifier">os</phrase></code>.
2090           </para>
2091         </listitem>
2092       </varlistentry>
2093       <varlistentry>
2094         <term>Returns:</term>
2095         <listitem>
2096           <para>
2097             <code><phrase role="identifier">os</phrase></code>
2098           </para>
2099         </listitem>
2100       </varlistentry>
2101     </variablelist>
2102   </section>
2103   <section id="context.stack">
2104     <title><anchor id="stack"/><link linkend="context.stack">Stack allocation</link></title>
2105     <para>
2106       The memory used by the stack is allocated/deallocated via a <emphasis>StackAllocator</emphasis>
2107       which is required to model a <emphasis>stack-allocator concept</emphasis>.
2108     </para>
2109     <bridgehead renderas="sect3" id="context.stack.h0">
2110       <phrase id="context.stack._emphasis_stack_allocator_concept__emphasis_"/><link
2111       linkend="context.stack._emphasis_stack_allocator_concept__emphasis_"><emphasis>stack-allocator
2112       concept</emphasis></link>
2113     </bridgehead>
2114     <para>
2115       A <emphasis>StackAllocator</emphasis> must satisfy the <emphasis>stack-allocator
2116       concept</emphasis> requirements shown in the following table, in which <code><phrase
2117       role="identifier">a</phrase></code> is an object of a <emphasis>StackAllocator</emphasis>
2118       type, <code><phrase role="identifier">sctx</phrase></code> is a <code><phrase
2119       role="identifier">stack_context</phrase></code>, and <code><phrase role="identifier">size</phrase></code>
2120       is a <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
2121       role="identifier">size_t</phrase></code>:
2122     </para>
2123     <informaltable frame="all">
2124       <tgroup cols="3">
2125         <thead>
2126           <row>
2127             <entry>
2128               <para>
2129                 expression
2130               </para>
2131             </entry>
2132             <entry>
2133               <para>
2134                 return type
2135               </para>
2136             </entry>
2137             <entry>
2138               <para>
2139                 notes
2140               </para>
2141             </entry>
2142           </row>
2143         </thead>
2144         <tbody>
2145           <row>
2146             <entry>
2147               <para>
2148                 <code><phrase role="identifier">a</phrase><phrase role="special">(</phrase><phrase
2149                 role="identifier">size</phrase><phrase role="special">)</phrase></code>
2150               </para>
2151             </entry>
2152             <entry>
2153             </entry>
2154             <entry>
2155               <para>
2156                 creates a stack allocator
2157               </para>
2158             </entry>
2159           </row>
2160           <row>
2161             <entry>
2162               <para>
2163                 <code><phrase role="identifier">a</phrase><phrase role="special">.</phrase><phrase
2164                 role="identifier">allocate</phrase><phrase role="special">()</phrase></code>
2165               </para>
2166             </entry>
2167             <entry>
2168               <para>
2169                 <code><phrase role="identifier">stack_context</phrase></code>
2170               </para>
2171             </entry>
2172             <entry>
2173               <para>
2174                 creates a stack
2175               </para>
2176             </entry>
2177           </row>
2178           <row>
2179             <entry>
2180               <para>
2181                 <code><phrase role="identifier">a</phrase><phrase role="special">.</phrase><phrase
2182                 role="identifier">deallocate</phrase><phrase role="special">(</phrase>
2183                 <phrase role="identifier">sctx</phrase><phrase role="special">)</phrase></code>
2184               </para>
2185             </entry>
2186             <entry>
2187               <para>
2188                 <code><phrase role="keyword">void</phrase></code>
2189               </para>
2190             </entry>
2191             <entry>
2192               <para>
2193                 deallocates the stack created by <code><phrase role="identifier">a</phrase><phrase
2194                 role="special">.</phrase><phrase role="identifier">allocate</phrase><phrase
2195                 role="special">()</phrase></code>
2196               </para>
2197             </entry>
2198           </row>
2199         </tbody>
2200       </tgroup>
2201     </informaltable>
2202     <important>
2203       <para>
2204         The implementation of <code><phrase role="identifier">allocate</phrase><phrase
2205         role="special">()</phrase></code> might include logic to protect against
2206         exceeding the context's available stack size rather than leaving it as undefined
2207         behaviour.
2208       </para>
2209     </important>
2210     <important>
2211       <para>
2212         Calling <code><phrase role="identifier">deallocate</phrase><phrase role="special">()</phrase></code>
2213         with a <code><phrase role="identifier">stack_context</phrase></code> not
2214         set by <code><phrase role="identifier">allocate</phrase><phrase role="special">()</phrase></code>
2215         results in undefined behaviour.
2216       </para>
2217     </important>
2218     <note>
2219       <para>
2220         The stack is not required to be aligned; alignment takes place inside <emphasis>execution_context</emphasis>.
2221       </para>
2222     </note>
2223     <note>
2224       <para>
2225         Depending on the architecture <code><phrase role="identifier">allocate</phrase><phrase
2226         role="special">()</phrase></code> stores an address from the top of the stack
2227         (growing downwards) or the bottom of the stack (growing upwards).
2228       </para>
2229     </note>
2230     <section id="context.stack.protected_fixedsize">
2231       <title><link linkend="context.stack.protected_fixedsize">Class <emphasis>protected_fixedsize</emphasis></link></title>
2232       <para>
2233         <emphasis role="bold">Boost.Context</emphasis> provides the class <emphasis>protected_fixedsize_stack</emphasis>
2234         which models the <emphasis>stack-allocator concept</emphasis>. It appends
2235         a guard page at the end of each stack to protect against exceeding the stack.
2236         If the guard page is accessed (read or write operation) a segmentation fault/access
2237         violation is generated by the operating system.
2238       </para>
2239       <important>
2240         <para>
2241           Using <emphasis>protected_fixedsize_stack</emphasis> is expensive. That
2242           is, launching a new coroutine with a new stack is expensive; the allocated
2243           stack is just as efficient to use as any other stack.
2244         </para>
2245       </important>
2246       <note>
2247         <para>
2248           The appended <code><phrase role="identifier">guard</phrase> <phrase role="identifier">page</phrase></code>
2249           is <emphasis role="bold">not</emphasis> mapped to physical memory, only
2250           virtual addresses are used.
2251         </para>
2252       </note>
2253 <programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">context</phrase><phrase role="special">/</phrase><phrase role="identifier">protected_fixedsize</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
2254
2255 <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">traitsT</phrase> <phrase role="special">&gt;</phrase>
2256 <phrase role="keyword">struct</phrase> <phrase role="identifier">basic_protected_fixedsize</phrase> <phrase role="special">{</phrase>
2257     <phrase role="keyword">typedef</phrase> <phrase role="identifier">traitT</phrase>  <phrase role="identifier">traits_type</phrase><phrase role="special">;</phrase>
2258
2259     <phrase role="identifier">basic_protected_fixesize</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">size</phrase> <phrase role="special">=</phrase> <phrase role="identifier">traits_type</phrase><phrase role="special">::</phrase><phrase role="identifier">default_size</phrase><phrase role="special">());</phrase>
2260
2261     <phrase role="identifier">stack_context</phrase> <phrase role="identifier">allocate</phrase><phrase role="special">();</phrase>
2262
2263     <phrase role="keyword">void</phrase> <phrase role="identifier">deallocate</phrase><phrase role="special">(</phrase> <phrase role="identifier">stack_context</phrase> <phrase role="special">&amp;);</phrase>
2264 <phrase role="special">}</phrase>
2265
2266 <phrase role="keyword">typedef</phrase> <phrase role="identifier">basic_protected_fixedsize</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">stack_traits</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">protected_fixedsize</phrase>
2267 </programlisting>
2268       <bridgehead renderas="sect4" id="context.stack.protected_fixedsize.h0">
2269         <phrase id="context.stack.protected_fixedsize._code__phrase_role__identifier__stack_context__phrase___phrase_role__identifier__allocate__phrase__phrase_role__special______phrase___code_"/><link
2270         linkend="context.stack.protected_fixedsize._code__phrase_role__identifier__stack_context__phrase___phrase_role__identifier__allocate__phrase__phrase_role__special______phrase___code_"><code><phrase
2271         role="identifier">stack_context</phrase> <phrase role="identifier">allocate</phrase><phrase
2272         role="special">()</phrase></code></link>
2273       </bridgehead>
2274       <variablelist>
2275         <title></title>
2276         <varlistentry>
2277           <term>Preconditions:</term>
2278           <listitem>
2279             <para>
2280               <code><phrase role="identifier">traits_type</phrase><phrase role="special">::</phrase><phrase
2281               role="identifier">minimum</phrase><phrase role="special">:</phrase><phrase
2282               role="identifier">size</phrase><phrase role="special">()</phrase>
2283               <phrase role="special">&lt;=</phrase> <phrase role="identifier">size</phrase></code>
2284               and <code><phrase role="special">!</phrase> <phrase role="identifier">traits_type</phrase><phrase
2285               role="special">::</phrase><phrase role="identifier">is_unbounded</phrase><phrase
2286               role="special">()</phrase> <phrase role="special">&amp;&amp;</phrase>
2287               <phrase role="special">(</phrase> <phrase role="identifier">traits_type</phrase><phrase
2288               role="special">::</phrase><phrase role="identifier">maximum</phrase><phrase
2289               role="special">:</phrase><phrase role="identifier">size</phrase><phrase
2290               role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase
2291               role="identifier">size</phrase><phrase role="special">)</phrase></code>.
2292             </para>
2293           </listitem>
2294         </varlistentry>
2295         <varlistentry>
2296           <term>Effects:</term>
2297           <listitem>
2298             <para>
2299               Allocates memory of at least <code><phrase role="identifier">size</phrase></code>
2300               Bytes and stores a pointer to the stack and its actual size in <code><phrase
2301               role="identifier">sctx</phrase></code>. Depending on the architecture
2302               (the stack grows downwards/upwards) the stored address is the highest/lowest
2303               address of the stack.
2304             </para>
2305           </listitem>
2306         </varlistentry>
2307       </variablelist>
2308       <bridgehead renderas="sect4" id="context.stack.protected_fixedsize.h1">
2309         <phrase id="context.stack.protected_fixedsize._code__phrase_role__keyword__void__phrase___phrase_role__identifier__deallocate__phrase__phrase_role__special_____phrase___phrase_role__identifier__stack_context__phrase___phrase_role__special___amp___phrase___phrase_role__identifier__sctx__phrase__phrase_role__special_____phrase___code_"/><link
2310         linkend="context.stack.protected_fixedsize._code__phrase_role__keyword__void__phrase___phrase_role__identifier__deallocate__phrase__phrase_role__special_____phrase___phrase_role__identifier__stack_context__phrase___phrase_role__special___amp___phrase___phrase_role__identifier__sctx__phrase__phrase_role__special_____phrase___code_"><code><phrase
2311         role="keyword">void</phrase> <phrase role="identifier">deallocate</phrase><phrase
2312         role="special">(</phrase> <phrase role="identifier">stack_context</phrase>
2313         <phrase role="special">&amp;</phrase> <phrase role="identifier">sctx</phrase><phrase
2314         role="special">)</phrase></code></link>
2315       </bridgehead>
2316       <variablelist>
2317         <title></title>
2318         <varlistentry>
2319           <term>Preconditions:</term>
2320           <listitem>
2321             <para>
2322               <code><phrase role="identifier">sctx</phrase><phrase role="special">.</phrase><phrase
2323               role="identifier">sp</phrase></code> is valid, <code><phrase role="identifier">traits_type</phrase><phrase
2324               role="special">::</phrase><phrase role="identifier">minimum</phrase><phrase
2325               role="special">:</phrase><phrase role="identifier">size</phrase><phrase
2326               role="special">()</phrase> <phrase role="special">&lt;=</phrase> <phrase
2327               role="identifier">sctx</phrase><phrase role="special">.</phrase><phrase
2328               role="identifier">size</phrase></code> and <code><phrase role="special">!</phrase>
2329               <phrase role="identifier">traits_type</phrase><phrase role="special">::</phrase><phrase
2330               role="identifier">is_unbounded</phrase><phrase role="special">()</phrase>
2331               <phrase role="special">&amp;&amp;</phrase> <phrase role="special">(</phrase>
2332               <phrase role="identifier">traits_type</phrase><phrase role="special">::</phrase><phrase
2333               role="identifier">maximum</phrase><phrase role="special">:</phrase><phrase
2334               role="identifier">size</phrase><phrase role="special">()</phrase>
2335               <phrase role="special">&gt;=</phrase> <phrase role="identifier">sctx</phrase><phrase
2336               role="special">.</phrase><phrase role="identifier">size</phrase><phrase
2337               role="special">)</phrase></code>.
2338             </para>
2339           </listitem>
2340         </varlistentry>
2341         <varlistentry>
2342           <term>Effects:</term>
2343           <listitem>
2344             <para>
2345               Deallocates the stack space.
2346             </para>
2347           </listitem>
2348         </varlistentry>
2349       </variablelist>
2350     </section>
2351     <section id="context.stack.pooled_fixedsize">
2352       <title><link linkend="context.stack.pooled_fixedsize">Class <emphasis>pooled_fixedsize_stack</emphasis></link></title>
2353       <para>
2354         <emphasis role="bold">Boost.Context</emphasis> provides the class <emphasis>pooled_fixedsize_stack</emphasis>
2355         which models the <emphasis>stack-allocator concept</emphasis>. In contrast
2356         to <emphasis>protected_fixedsize_stack</emphasis> it does not append a guard
2357         page at the end of each stack. The memory is managed internally by <ulink
2358         url="http://www.boost.org/doc/libs/release/libs/pool/doc/html/boost/pool.html"><code><phrase
2359         role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
2360         role="identifier">pool</phrase><phrase role="special">&lt;&gt;</phrase></code></ulink>.
2361       </para>
2362 <programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">context</phrase><phrase role="special">/</phrase><phrase role="identifier">pooled_fixedsize_stack</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
2363
2364 <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">traitsT</phrase> <phrase role="special">&gt;</phrase>
2365 <phrase role="keyword">struct</phrase> <phrase role="identifier">basic_pooled_fixedsize_stack</phrase> <phrase role="special">{</phrase>
2366     <phrase role="keyword">typedef</phrase> <phrase role="identifier">traitT</phrase>  <phrase role="identifier">traits_type</phrase><phrase role="special">;</phrase>
2367
2368     <phrase role="identifier">basic_pooled_fixedsize_stack</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">stack_size</phrase> <phrase role="special">=</phrase> <phrase role="identifier">traits_type</phrase><phrase role="special">::</phrase><phrase role="identifier">default_size</phrase><phrase role="special">(),</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">next_size</phrase> <phrase role="special">=</phrase> <phrase role="number">32</phrase><phrase role="special">,</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">max_size</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
2369
2370     <phrase role="identifier">stack_context</phrase> <phrase role="identifier">allocate</phrase><phrase role="special">();</phrase>
2371
2372     <phrase role="keyword">void</phrase> <phrase role="identifier">deallocate</phrase><phrase role="special">(</phrase> <phrase role="identifier">stack_context</phrase> <phrase role="special">&amp;);</phrase>
2373 <phrase role="special">}</phrase>
2374
2375 <phrase role="keyword">typedef</phrase> <phrase role="identifier">basic_pooled_fixedsize_stack</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">stack_traits</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">pooled_fixedsize_stack</phrase><phrase role="special">;</phrase>
2376 </programlisting>
2377       <bridgehead renderas="sect4" id="context.stack.pooled_fixedsize.h0">
2378         <phrase id="context.stack.pooled_fixedsize._code__phrase_role__identifier__basic_pooled_fixedsize_stack__phrase__phrase_role__special_____phrase__phrase_role__identifier__std__phrase__phrase_role__special______phrase__phrase_role__identifier__size_t__phrase___phrase_role__identifier__stack_size__phrase__phrase_role__special_____phrase___phrase_role__identifier__std__phrase__phrase_role__special______phrase__phrase_role__identifier__size_t__phrase___phrase_role__identifier__next_size__phrase__phrase_role__special_____phrase___phrase_role__identifier__std__phrase__phrase_role__special______phrase__phrase_role__identifier__size_t__phrase___phrase_role__identifier__max_size__phrase__phrase_role__special_____phrase___code_"/><link
2379         linkend="context.stack.pooled_fixedsize._code__phrase_role__identifier__basic_pooled_fixedsize_stack__phrase__phrase_role__special_____phrase__phrase_role__identifier__std__phrase__phrase_role__special______phrase__phrase_role__identifier__size_t__phrase___phrase_role__identifier__stack_size__phrase__phrase_role__special_____phrase___phrase_role__identifier__std__phrase__phrase_role__special______phrase__phrase_role__identifier__size_t__phrase___phrase_role__identifier__next_size__phrase__phrase_role__special_____phrase___phrase_role__identifier__std__phrase__phrase_role__special______phrase__phrase_role__identifier__size_t__phrase___phrase_role__identifier__max_size__phrase__phrase_role__special_____phrase___code_"><code><phrase
2380         role="identifier">basic_pooled_fixedsize_stack</phrase><phrase role="special">(</phrase><phrase
2381         role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase>
2382         <phrase role="identifier">stack_size</phrase><phrase role="special">,</phrase>
2383         <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
2384         role="identifier">size_t</phrase> <phrase role="identifier">next_size</phrase><phrase
2385         role="special">,</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
2386         role="identifier">size_t</phrase> <phrase role="identifier">max_size</phrase><phrase
2387         role="special">)</phrase></code></link>
2388       </bridgehead>
2389       <variablelist>
2390         <title></title>
2391         <varlistentry>
2392           <term>Preconditions:</term>
2393           <listitem>
2394             <para>
2395               <code><phrase role="special">!</phrase> <phrase role="identifier">traits_type</phrase><phrase
2396               role="special">::</phrase><phrase role="identifier">is_unbounded</phrase><phrase
2397               role="special">()</phrase> <phrase role="special">&amp;&amp;</phrase>
2398               <phrase role="special">(</phrase> <phrase role="identifier">traits_type</phrase><phrase
2399               role="special">::</phrase><phrase role="identifier">maximum</phrase><phrase
2400               role="special">:</phrase><phrase role="identifier">size</phrase><phrase
2401               role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase
2402               role="identifier">stack_size</phrase><phrase role="special">)</phrase></code>
2403               and <code><phrase role="number">0</phrase> <phrase role="special">&lt;</phrase>
2404               <phrase role="identifier">nest_size</phrase></code>.
2405             </para>
2406           </listitem>
2407         </varlistentry>
2408         <varlistentry>
2409           <term>Effects:</term>
2410           <listitem>
2411             <para>
2412               Allocates memory of at least <code><phrase role="identifier">stack_size</phrase></code>
2413               Bytes and stores a pointer to the stack and its actual size in <code><phrase
2414               role="identifier">sctx</phrase></code>. Depending on the architecture
2415               (the stack grows downwards/upwards) the stored address is the highest/lowest
2416               address of the stack. Argument <code><phrase role="identifier">next_size</phrase></code>
2417               determines the number of stacks to request from the system the first
2418               time that <code><phrase role="special">*</phrase><phrase role="keyword">this</phrase></code>
2419               needs to allocate system memory. The third argument <code><phrase role="identifier">max_size</phrase></code>
2420               controls how many memory might be allocated for stacks - a value of
2421               zero means no uper limit.
2422             </para>
2423           </listitem>
2424         </varlistentry>
2425       </variablelist>
2426       <bridgehead renderas="sect4" id="context.stack.pooled_fixedsize.h1">
2427         <phrase id="context.stack.pooled_fixedsize._code__phrase_role__identifier__stack_context__phrase___phrase_role__identifier__allocate__phrase__phrase_role__special______phrase___code_"/><link
2428         linkend="context.stack.pooled_fixedsize._code__phrase_role__identifier__stack_context__phrase___phrase_role__identifier__allocate__phrase__phrase_role__special______phrase___code_"><code><phrase
2429         role="identifier">stack_context</phrase> <phrase role="identifier">allocate</phrase><phrase
2430         role="special">()</phrase></code></link>
2431       </bridgehead>
2432       <variablelist>
2433         <title></title>
2434         <varlistentry>
2435           <term>Preconditions:</term>
2436           <listitem>
2437             <para>
2438               <code><phrase role="special">!</phrase> <phrase role="identifier">traits_type</phrase><phrase
2439               role="special">::</phrase><phrase role="identifier">is_unbounded</phrase><phrase
2440               role="special">()</phrase> <phrase role="special">&amp;&amp;</phrase>
2441               <phrase role="special">(</phrase> <phrase role="identifier">traits_type</phrase><phrase
2442               role="special">::</phrase><phrase role="identifier">maximum</phrase><phrase
2443               role="special">:</phrase><phrase role="identifier">size</phrase><phrase
2444               role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase
2445               role="identifier">stack_size</phrase><phrase role="special">)</phrase></code>.
2446             </para>
2447           </listitem>
2448         </varlistentry>
2449         <varlistentry>
2450           <term>Effects:</term>
2451           <listitem>
2452             <para>
2453               Allocates memory of at least <code><phrase role="identifier">stack_size</phrase></code>
2454               Bytes and stores a pointer to the stack and its actual size in <code><phrase
2455               role="identifier">sctx</phrase></code>. Depending on the architecture
2456               (the stack grows downwards/upwards) the stored address is the highest/lowest
2457               address of the stack.
2458             </para>
2459           </listitem>
2460         </varlistentry>
2461       </variablelist>
2462       <bridgehead renderas="sect4" id="context.stack.pooled_fixedsize.h2">
2463         <phrase id="context.stack.pooled_fixedsize._code__phrase_role__keyword__void__phrase___phrase_role__identifier__deallocate__phrase__phrase_role__special_____phrase___phrase_role__identifier__stack_context__phrase___phrase_role__special___amp___phrase___phrase_role__identifier__sctx__phrase__phrase_role__special_____phrase___code_"/><link
2464         linkend="context.stack.pooled_fixedsize._code__phrase_role__keyword__void__phrase___phrase_role__identifier__deallocate__phrase__phrase_role__special_____phrase___phrase_role__identifier__stack_context__phrase___phrase_role__special___amp___phrase___phrase_role__identifier__sctx__phrase__phrase_role__special_____phrase___code_"><code><phrase
2465         role="keyword">void</phrase> <phrase role="identifier">deallocate</phrase><phrase
2466         role="special">(</phrase> <phrase role="identifier">stack_context</phrase>
2467         <phrase role="special">&amp;</phrase> <phrase role="identifier">sctx</phrase><phrase
2468         role="special">)</phrase></code></link>
2469       </bridgehead>
2470       <variablelist>
2471         <title></title>
2472         <varlistentry>
2473           <term>Preconditions:</term>
2474           <listitem>
2475             <para>
2476               <code><phrase role="identifier">sctx</phrase><phrase role="special">.</phrase><phrase
2477               role="identifier">sp</phrase></code> is valid, <code><phrase role="special">!</phrase>
2478               <phrase role="identifier">traits_type</phrase><phrase role="special">::</phrase><phrase
2479               role="identifier">is_unbounded</phrase><phrase role="special">()</phrase>
2480               <phrase role="special">&amp;&amp;</phrase> <phrase role="special">(</phrase>
2481               <phrase role="identifier">traits_type</phrase><phrase role="special">::</phrase><phrase
2482               role="identifier">maximum</phrase><phrase role="special">:</phrase><phrase
2483               role="identifier">size</phrase><phrase role="special">()</phrase>
2484               <phrase role="special">&gt;=</phrase> <phrase role="identifier">sctx</phrase><phrase
2485               role="special">.</phrase><phrase role="identifier">size</phrase><phrase
2486               role="special">)</phrase></code>.
2487             </para>
2488           </listitem>
2489         </varlistentry>
2490         <varlistentry>
2491           <term>Effects:</term>
2492           <listitem>
2493             <para>
2494               Deallocates the stack space.
2495             </para>
2496           </listitem>
2497         </varlistentry>
2498       </variablelist>
2499     </section>
2500     <section id="context.stack.fixedsize">
2501       <title><link linkend="context.stack.fixedsize">Class <emphasis>fixedsize_stack</emphasis></link></title>
2502       <para>
2503         <emphasis role="bold">Boost.Context</emphasis> provides the class <emphasis>fixedsize_stack</emphasis>
2504         which models the <emphasis>stack-allocator concept</emphasis>. In contrast
2505         to <emphasis>protected_fixedsize_stack</emphasis> it does not append a guard
2506         page at the end of each stack. The memory is simply managed by <code><phrase
2507         role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">malloc</phrase><phrase
2508         role="special">()</phrase></code> and <code><phrase role="identifier">std</phrase><phrase
2509         role="special">::</phrase><phrase role="identifier">free</phrase><phrase
2510         role="special">()</phrase></code>.
2511       </para>
2512 <programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">context</phrase><phrase role="special">/</phrase><phrase role="identifier">fixedsize_stack</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
2513
2514 <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">traitsT</phrase> <phrase role="special">&gt;</phrase>
2515 <phrase role="keyword">struct</phrase> <phrase role="identifier">basic_fixedsize_stack</phrase> <phrase role="special">{</phrase>
2516     <phrase role="keyword">typedef</phrase> <phrase role="identifier">traitT</phrase>  <phrase role="identifier">traits_type</phrase><phrase role="special">;</phrase>
2517
2518     <phrase role="identifier">basic_fixesize_stack</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">size</phrase> <phrase role="special">=</phrase> <phrase role="identifier">traits_type</phrase><phrase role="special">::</phrase><phrase role="identifier">default_size</phrase><phrase role="special">());</phrase>
2519
2520     <phrase role="identifier">stack_context</phrase> <phrase role="identifier">allocate</phrase><phrase role="special">();</phrase>
2521
2522     <phrase role="keyword">void</phrase> <phrase role="identifier">deallocate</phrase><phrase role="special">(</phrase> <phrase role="identifier">stack_context</phrase> <phrase role="special">&amp;);</phrase>
2523 <phrase role="special">}</phrase>
2524
2525 <phrase role="keyword">typedef</phrase> <phrase role="identifier">basic_fixedsize_stack</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">stack_traits</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">fixedsize_stack</phrase><phrase role="special">;</phrase>
2526 </programlisting>
2527       <bridgehead renderas="sect4" id="context.stack.fixedsize.h0">
2528         <phrase id="context.stack.fixedsize._code__phrase_role__identifier__stack_context__phrase___phrase_role__identifier__allocate__phrase__phrase_role__special______phrase___code_"/><link
2529         linkend="context.stack.fixedsize._code__phrase_role__identifier__stack_context__phrase___phrase_role__identifier__allocate__phrase__phrase_role__special______phrase___code_"><code><phrase
2530         role="identifier">stack_context</phrase> <phrase role="identifier">allocate</phrase><phrase
2531         role="special">()</phrase></code></link>
2532       </bridgehead>
2533       <variablelist>
2534         <title></title>
2535         <varlistentry>
2536           <term>Preconditions:</term>
2537           <listitem>
2538             <para>
2539               <code><phrase role="identifier">traits_type</phrase><phrase role="special">::</phrase><phrase
2540               role="identifier">minimum</phrase><phrase role="special">:</phrase><phrase
2541               role="identifier">size</phrase><phrase role="special">()</phrase>
2542               <phrase role="special">&lt;=</phrase> <phrase role="identifier">size</phrase></code>
2543               and <code><phrase role="special">!</phrase> <phrase role="identifier">traits_type</phrase><phrase
2544               role="special">::</phrase><phrase role="identifier">is_unbounded</phrase><phrase
2545               role="special">()</phrase> <phrase role="special">&amp;&amp;</phrase>
2546               <phrase role="special">(</phrase> <phrase role="identifier">traits_type</phrase><phrase
2547               role="special">::</phrase><phrase role="identifier">maximum</phrase><phrase
2548               role="special">:</phrase><phrase role="identifier">size</phrase><phrase
2549               role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase
2550               role="identifier">size</phrase><phrase role="special">)</phrase></code>.
2551             </para>
2552           </listitem>
2553         </varlistentry>
2554         <varlistentry>
2555           <term>Effects:</term>
2556           <listitem>
2557             <para>
2558               Allocates memory of at least <code><phrase role="identifier">size</phrase></code>
2559               Bytes and stores a pointer to the stack and its actual size in <code><phrase
2560               role="identifier">sctx</phrase></code>. Depending on the architecture
2561               (the stack grows downwards/upwards) the stored address is the highest/lowest
2562               address of the stack.
2563             </para>
2564           </listitem>
2565         </varlistentry>
2566       </variablelist>
2567       <bridgehead renderas="sect4" id="context.stack.fixedsize.h1">
2568         <phrase id="context.stack.fixedsize._code__phrase_role__keyword__void__phrase___phrase_role__identifier__deallocate__phrase__phrase_role__special_____phrase___phrase_role__identifier__stack_context__phrase___phrase_role__special___amp___phrase___phrase_role__identifier__sctx__phrase__phrase_role__special_____phrase___code_"/><link
2569         linkend="context.stack.fixedsize._code__phrase_role__keyword__void__phrase___phrase_role__identifier__deallocate__phrase__phrase_role__special_____phrase___phrase_role__identifier__stack_context__phrase___phrase_role__special___amp___phrase___phrase_role__identifier__sctx__phrase__phrase_role__special_____phrase___code_"><code><phrase
2570         role="keyword">void</phrase> <phrase role="identifier">deallocate</phrase><phrase
2571         role="special">(</phrase> <phrase role="identifier">stack_context</phrase>
2572         <phrase role="special">&amp;</phrase> <phrase role="identifier">sctx</phrase><phrase
2573         role="special">)</phrase></code></link>
2574       </bridgehead>
2575       <variablelist>
2576         <title></title>
2577         <varlistentry>
2578           <term>Preconditions:</term>
2579           <listitem>
2580             <para>
2581               <code><phrase role="identifier">sctx</phrase><phrase role="special">.</phrase><phrase
2582               role="identifier">sp</phrase></code> is valid, <code><phrase role="identifier">traits_type</phrase><phrase
2583               role="special">::</phrase><phrase role="identifier">minimum</phrase><phrase
2584               role="special">:</phrase><phrase role="identifier">size</phrase><phrase
2585               role="special">()</phrase> <phrase role="special">&lt;=</phrase> <phrase
2586               role="identifier">sctx</phrase><phrase role="special">.</phrase><phrase
2587               role="identifier">size</phrase></code> and <code><phrase role="special">!</phrase>
2588               <phrase role="identifier">traits_type</phrase><phrase role="special">::</phrase><phrase
2589               role="identifier">is_unbounded</phrase><phrase role="special">()</phrase>
2590               <phrase role="special">&amp;&amp;</phrase> <phrase role="special">(</phrase>
2591               <phrase role="identifier">traits_type</phrase><phrase role="special">::</phrase><phrase
2592               role="identifier">maximum</phrase><phrase role="special">:</phrase><phrase
2593               role="identifier">size</phrase><phrase role="special">()</phrase>
2594               <phrase role="special">&gt;=</phrase> <phrase role="identifier">sctx</phrase><phrase
2595               role="special">.</phrase><phrase role="identifier">size</phrase><phrase
2596               role="special">)</phrase></code>.
2597             </para>
2598           </listitem>
2599         </varlistentry>
2600         <varlistentry>
2601           <term>Effects:</term>
2602           <listitem>
2603             <para>
2604               Deallocates the stack space.
2605             </para>
2606           </listitem>
2607         </varlistentry>
2608       </variablelist>
2609     </section>
2610     <section id="context.stack.segmented">
2611       <title><link linkend="context.stack.segmented">Class <emphasis>segmented_stack</emphasis></link></title>
2612       <para>
2613         <emphasis role="bold">Boost.Context</emphasis> supports usage of a <emphasis>segmented_stack</emphasis>,
2614         e. g. the size of the stack grows on demand. The coroutine is created with
2615         a minimal stack size and will be increased as required. Class <emphasis>segmented_stack</emphasis>
2616         models the <emphasis>stack-allocator concept</emphasis>. In contrast to
2617         <emphasis>protected_fixedsize_stack</emphasis> and <emphasis>fixedsize_stack</emphasis>
2618         it creates a stack which grows on demand.
2619       </para>
2620       <note>
2621         <para>
2622           Segmented stacks are currently only supported by <emphasis role="bold">gcc</emphasis>
2623           from version <emphasis role="bold">4.7</emphasis> <emphasis role="bold">clang</emphasis>
2624           from version <emphasis role="bold">3.4</emphasis> onwards. In order to
2625           use a __segmented_stack__ <emphasis role="bold">Boost.Context</emphasis>
2626           must be built with property <code><phrase role="identifier">segmented</phrase><phrase
2627           role="special">-</phrase><phrase role="identifier">stacks</phrase></code>,
2628           e.g. <emphasis role="bold">toolset=gcc segmented-stacks=on</emphasis> at
2629           b2/bjam command line.
2630         </para>
2631       </note>
2632 <programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">context</phrase><phrase role="special">/</phrase><phrase role="identifier">segmented_stack</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
2633
2634 <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">traitsT</phrase> <phrase role="special">&gt;</phrase>
2635 <phrase role="keyword">struct</phrase> <phrase role="identifier">basic_segmented_stack</phrase> <phrase role="special">{</phrase>
2636     <phrase role="keyword">typedef</phrase> <phrase role="identifier">traitT</phrase>  <phrase role="identifier">traits_type</phrase><phrase role="special">;</phrase>
2637
2638     <phrase role="identifier">basic_segmented_stack</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">size</phrase> <phrase role="special">=</phrase> <phrase role="identifier">traits_type</phrase><phrase role="special">::</phrase><phrase role="identifier">default_size</phrase><phrase role="special">());</phrase>
2639
2640     <phrase role="identifier">stack_context</phrase> <phrase role="identifier">allocate</phrase><phrase role="special">();</phrase>
2641
2642     <phrase role="keyword">void</phrase> <phrase role="identifier">deallocate</phrase><phrase role="special">(</phrase> <phrase role="identifier">stack_context</phrase> <phrase role="special">&amp;);</phrase>
2643 <phrase role="special">}</phrase>
2644
2645 <phrase role="keyword">typedef</phrase> <phrase role="identifier">basic_segmented_stack</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">stack_traits</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">segmented_stack</phrase><phrase role="special">;</phrase>
2646 </programlisting>
2647       <bridgehead renderas="sect4" id="context.stack.segmented.h0">
2648         <phrase id="context.stack.segmented._code__phrase_role__identifier__stack_context__phrase___phrase_role__identifier__allocate__phrase__phrase_role__special______phrase___code_"/><link
2649         linkend="context.stack.segmented._code__phrase_role__identifier__stack_context__phrase___phrase_role__identifier__allocate__phrase__phrase_role__special______phrase___code_"><code><phrase
2650         role="identifier">stack_context</phrase> <phrase role="identifier">allocate</phrase><phrase
2651         role="special">()</phrase></code></link>
2652       </bridgehead>
2653       <variablelist>
2654         <title></title>
2655         <varlistentry>
2656           <term>Preconditions:</term>
2657           <listitem>
2658             <para>
2659               <code><phrase role="identifier">traits_type</phrase><phrase role="special">::</phrase><phrase
2660               role="identifier">minimum</phrase><phrase role="special">:</phrase><phrase
2661               role="identifier">size</phrase><phrase role="special">()</phrase>
2662               <phrase role="special">&lt;=</phrase> <phrase role="identifier">size</phrase></code>
2663               and <code><phrase role="special">!</phrase> <phrase role="identifier">traits_type</phrase><phrase
2664               role="special">::</phrase><phrase role="identifier">is_unbounded</phrase><phrase
2665               role="special">()</phrase> <phrase role="special">&amp;&amp;</phrase>
2666               <phrase role="special">(</phrase> <phrase role="identifier">traits_type</phrase><phrase
2667               role="special">::</phrase><phrase role="identifier">maximum</phrase><phrase
2668               role="special">:</phrase><phrase role="identifier">size</phrase><phrase
2669               role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase
2670               role="identifier">size</phrase><phrase role="special">)</phrase></code>.
2671             </para>
2672           </listitem>
2673         </varlistentry>
2674         <varlistentry>
2675           <term>Effects:</term>
2676           <listitem>
2677             <para>
2678               Allocates memory of at least <code><phrase role="identifier">size</phrase></code>
2679               Bytes and stores a pointer to the stack and its actual size in <code><phrase
2680               role="identifier">sctx</phrase></code>. Depending on the architecture
2681               (the stack grows downwards/upwards) the stored address is the highest/lowest
2682               address of the stack.
2683             </para>
2684           </listitem>
2685         </varlistentry>
2686       </variablelist>
2687       <bridgehead renderas="sect4" id="context.stack.segmented.h1">
2688         <phrase id="context.stack.segmented._code__phrase_role__keyword__void__phrase___phrase_role__identifier__deallocate__phrase__phrase_role__special_____phrase___phrase_role__identifier__stack_context__phrase___phrase_role__special___amp___phrase___phrase_role__identifier__sctx__phrase__phrase_role__special_____phrase___code_"/><link
2689         linkend="context.stack.segmented._code__phrase_role__keyword__void__phrase___phrase_role__identifier__deallocate__phrase__phrase_role__special_____phrase___phrase_role__identifier__stack_context__phrase___phrase_role__special___amp___phrase___phrase_role__identifier__sctx__phrase__phrase_role__special_____phrase___code_"><code><phrase
2690         role="keyword">void</phrase> <phrase role="identifier">deallocate</phrase><phrase
2691         role="special">(</phrase> <phrase role="identifier">stack_context</phrase>
2692         <phrase role="special">&amp;</phrase> <phrase role="identifier">sctx</phrase><phrase
2693         role="special">)</phrase></code></link>
2694       </bridgehead>
2695       <variablelist>
2696         <title></title>
2697         <varlistentry>
2698           <term>Preconditions:</term>
2699           <listitem>
2700             <para>
2701               <code><phrase role="identifier">sctx</phrase><phrase role="special">.</phrase><phrase
2702               role="identifier">sp</phrase></code> is valid, <code><phrase role="identifier">traits_type</phrase><phrase
2703               role="special">::</phrase><phrase role="identifier">minimum</phrase><phrase
2704               role="special">:</phrase><phrase role="identifier">size</phrase><phrase
2705               role="special">()</phrase> <phrase role="special">&lt;=</phrase> <phrase
2706               role="identifier">sctx</phrase><phrase role="special">.</phrase><phrase
2707               role="identifier">size</phrase></code> and <code><phrase role="special">!</phrase>
2708               <phrase role="identifier">traits_type</phrase><phrase role="special">::</phrase><phrase
2709               role="identifier">is_unbounded</phrase><phrase role="special">()</phrase>
2710               <phrase role="special">&amp;&amp;</phrase> <phrase role="special">(</phrase>
2711               <phrase role="identifier">traits_type</phrase><phrase role="special">::</phrase><phrase
2712               role="identifier">maximum</phrase><phrase role="special">:</phrase><phrase
2713               role="identifier">size</phrase><phrase role="special">()</phrase>
2714               <phrase role="special">&gt;=</phrase> <phrase role="identifier">sctx</phrase><phrase
2715               role="special">.</phrase><phrase role="identifier">size</phrase><phrase
2716               role="special">)</phrase></code>.
2717             </para>
2718           </listitem>
2719         </varlistentry>
2720         <varlistentry>
2721           <term>Effects:</term>
2722           <listitem>
2723             <para>
2724               Deallocates the stack space.
2725             </para>
2726           </listitem>
2727         </varlistentry>
2728       </variablelist>
2729       <note>
2730         <para>
2731           If the library is compiled for segmented stacks, __segmented_stack__ is
2732           the only available stack allocator.
2733         </para>
2734       </note>
2735     </section>
2736     <section id="context.stack.stack_traits">
2737       <title><link linkend="context.stack.stack_traits">Class <emphasis>stack_traits</emphasis></link></title>
2738       <para>
2739         <emphasis>stack_traits</emphasis> models a <emphasis>stack-traits</emphasis>
2740         providing a way to access certain properites defined by the enironment. Stack
2741         allocators use <emphasis>stack-traits</emphasis> to allocate stacks.
2742       </para>
2743 <programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">context</phrase><phrase role="special">/</phrase><phrase role="identifier">stack_traits</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
2744
2745 <phrase role="keyword">struct</phrase> <phrase role="identifier">stack_traits</phrase> <phrase role="special">{</phrase>
2746     <phrase role="keyword">static</phrase> <phrase role="keyword">bool</phrase> <phrase role="identifier">is_unbounded</phrase><phrase role="special">()</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
2747
2748     <phrase role="keyword">static</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">page_size</phrase><phrase role="special">()</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
2749
2750     <phrase role="keyword">static</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">default_size</phrase><phrase role="special">()</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
2751
2752     <phrase role="keyword">static</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">minimum_size</phrase><phrase role="special">()</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
2753
2754     <phrase role="keyword">static</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">maximum_size</phrase><phrase role="special">()</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
2755 <phrase role="special">}</phrase>
2756 </programlisting>
2757       <bridgehead renderas="sect4" id="context.stack.stack_traits.h0">
2758         <phrase id="context.stack.stack_traits._code__phrase_role__keyword__static__phrase___phrase_role__keyword__bool__phrase___phrase_role__identifier__is_unbounded__phrase__phrase_role__special______phrase___code_"/><link
2759         linkend="context.stack.stack_traits._code__phrase_role__keyword__static__phrase___phrase_role__keyword__bool__phrase___phrase_role__identifier__is_unbounded__phrase__phrase_role__special______phrase___code_"><code><phrase
2760         role="keyword">static</phrase> <phrase role="keyword">bool</phrase> <phrase
2761         role="identifier">is_unbounded</phrase><phrase role="special">()</phrase></code></link>
2762       </bridgehead>
2763       <variablelist>
2764         <title></title>
2765         <varlistentry>
2766           <term>Returns:</term>
2767           <listitem>
2768             <para>
2769               Returns <code><phrase role="keyword">true</phrase></code> if the environment
2770               defines no limit for the size of a stack.
2771             </para>
2772           </listitem>
2773         </varlistentry>
2774         <varlistentry>
2775           <term>Throws:</term>
2776           <listitem>
2777             <para>
2778               Nothing.
2779             </para>
2780           </listitem>
2781         </varlistentry>
2782       </variablelist>
2783       <bridgehead renderas="sect4" id="context.stack.stack_traits.h1">
2784         <phrase id="context.stack.stack_traits._code__phrase_role__keyword__static__phrase___phrase_role__identifier__std__phrase__phrase_role__special______phrase__phrase_role__identifier__size_t__phrase___phrase_role__identifier__page_size__phrase__phrase_role__special______phrase___code_"/><link
2785         linkend="context.stack.stack_traits._code__phrase_role__keyword__static__phrase___phrase_role__identifier__std__phrase__phrase_role__special______phrase__phrase_role__identifier__size_t__phrase___phrase_role__identifier__page_size__phrase__phrase_role__special______phrase___code_"><code><phrase
2786         role="keyword">static</phrase> <phrase role="identifier">std</phrase><phrase
2787         role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase
2788         role="identifier">page_size</phrase><phrase role="special">()</phrase></code></link>
2789       </bridgehead>
2790       <variablelist>
2791         <title></title>
2792         <varlistentry>
2793           <term>Returns:</term>
2794           <listitem>
2795             <para>
2796               Returns the page size in bytes.
2797             </para>
2798           </listitem>
2799         </varlistentry>
2800         <varlistentry>
2801           <term>Throws:</term>
2802           <listitem>
2803             <para>
2804               Nothing.
2805             </para>
2806           </listitem>
2807         </varlistentry>
2808       </variablelist>
2809       <bridgehead renderas="sect4" id="context.stack.stack_traits.h2">
2810         <phrase id="context.stack.stack_traits._code__phrase_role__keyword__static__phrase___phrase_role__identifier__std__phrase__phrase_role__special______phrase__phrase_role__identifier__size_t__phrase___phrase_role__identifier__default_size__phrase__phrase_role__special______phrase___code_"/><link
2811         linkend="context.stack.stack_traits._code__phrase_role__keyword__static__phrase___phrase_role__identifier__std__phrase__phrase_role__special______phrase__phrase_role__identifier__size_t__phrase___phrase_role__identifier__default_size__phrase__phrase_role__special______phrase___code_"><code><phrase
2812         role="keyword">static</phrase> <phrase role="identifier">std</phrase><phrase
2813         role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase
2814         role="identifier">default_size</phrase><phrase role="special">()</phrase></code></link>
2815       </bridgehead>
2816       <variablelist>
2817         <title></title>
2818         <varlistentry>
2819           <term>Returns:</term>
2820           <listitem>
2821             <para>
2822               Returns a default stack size, which may be platform specific. If the
2823               stack is unbounded then the present implementation returns the maximum
2824               of <code><phrase role="number">64</phrase> <phrase role="identifier">kB</phrase></code>
2825               and <code><phrase role="identifier">minimum_size</phrase><phrase role="special">()</phrase></code>.
2826             </para>
2827           </listitem>
2828         </varlistentry>
2829         <varlistentry>
2830           <term>Throws:</term>
2831           <listitem>
2832             <para>
2833               Nothing.
2834             </para>
2835           </listitem>
2836         </varlistentry>
2837       </variablelist>
2838       <bridgehead renderas="sect4" id="context.stack.stack_traits.h3">
2839         <phrase id="context.stack.stack_traits._code__phrase_role__keyword__static__phrase___phrase_role__identifier__std__phrase__phrase_role__special______phrase__phrase_role__identifier__size_t__phrase___phrase_role__identifier__minimum_size__phrase__phrase_role__special______phrase___code_"/><link
2840         linkend="context.stack.stack_traits._code__phrase_role__keyword__static__phrase___phrase_role__identifier__std__phrase__phrase_role__special______phrase__phrase_role__identifier__size_t__phrase___phrase_role__identifier__minimum_size__phrase__phrase_role__special______phrase___code_"><code><phrase
2841         role="keyword">static</phrase> <phrase role="identifier">std</phrase><phrase
2842         role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase
2843         role="identifier">minimum_size</phrase><phrase role="special">()</phrase></code></link>
2844       </bridgehead>
2845       <variablelist>
2846         <title></title>
2847         <varlistentry>
2848           <term>Returns:</term>
2849           <listitem>
2850             <para>
2851               Returns the minimum size in bytes of stack defined by the environment
2852               (Win32 4kB/Win64 8kB, defined by rlimit on POSIX).
2853             </para>
2854           </listitem>
2855         </varlistentry>
2856         <varlistentry>
2857           <term>Throws:</term>
2858           <listitem>
2859             <para>
2860               Nothing.
2861             </para>
2862           </listitem>
2863         </varlistentry>
2864       </variablelist>
2865       <bridgehead renderas="sect4" id="context.stack.stack_traits.h4">
2866         <phrase id="context.stack.stack_traits._code__phrase_role__keyword__static__phrase___phrase_role__identifier__std__phrase__phrase_role__special______phrase__phrase_role__identifier__size_t__phrase___phrase_role__identifier__maximum_size__phrase__phrase_role__special______phrase___code_"/><link
2867         linkend="context.stack.stack_traits._code__phrase_role__keyword__static__phrase___phrase_role__identifier__std__phrase__phrase_role__special______phrase__phrase_role__identifier__size_t__phrase___phrase_role__identifier__maximum_size__phrase__phrase_role__special______phrase___code_"><code><phrase
2868         role="keyword">static</phrase> <phrase role="identifier">std</phrase><phrase
2869         role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase
2870         role="identifier">maximum_size</phrase><phrase role="special">()</phrase></code></link>
2871       </bridgehead>
2872       <variablelist>
2873         <title></title>
2874         <varlistentry>
2875           <term>Preconditions:</term>
2876           <listitem>
2877             <para>
2878               <code><phrase role="identifier">is_unbounded</phrase><phrase role="special">()</phrase></code>
2879               returns <code><phrase role="keyword">false</phrase></code>.
2880             </para>
2881           </listitem>
2882         </varlistentry>
2883         <varlistentry>
2884           <term>Returns:</term>
2885           <listitem>
2886             <para>
2887               Returns the maximum size in bytes of stack defined by the environment.
2888             </para>
2889           </listitem>
2890         </varlistentry>
2891         <varlistentry>
2892           <term>Throws:</term>
2893           <listitem>
2894             <para>
2895               Nothing.
2896             </para>
2897           </listitem>
2898         </varlistentry>
2899       </variablelist>
2900     </section>
2901     <section id="context.stack.stack_context">
2902       <title><link linkend="context.stack.stack_context">Class <emphasis>stack_context</emphasis></link></title>
2903       <para>
2904         <emphasis role="bold">Boost.Context</emphasis> provides the class <emphasis>stack_context</emphasis>
2905         which will contain the stack pointer and the size of the stack. In case of
2906         a <emphasis>segmented_stack</emphasis>, <emphasis>stack_context</emphasis>
2907         contains some extra control structures.
2908       </para>
2909 <programlisting><phrase role="keyword">struct</phrase> <phrase role="identifier">stack_context</phrase> <phrase role="special">{</phrase>
2910     <phrase role="keyword">void</phrase>    <phrase role="special">*</phrase>   <phrase role="identifier">sp</phrase><phrase role="special">;</phrase>
2911     <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">size</phrase><phrase role="special">;</phrase>
2912
2913     <phrase role="comment">// might contain additional control structures</phrase>
2914     <phrase role="comment">// for segmented stacks</phrase>
2915 <phrase role="special">}</phrase>
2916 </programlisting>
2917       <bridgehead renderas="sect4" id="context.stack.stack_context.h0">
2918         <phrase id="context.stack.stack_context._code__phrase_role__keyword__void__phrase___phrase_role__special_____phrase___phrase_role__identifier__sp__phrase___code_"/><link
2919         linkend="context.stack.stack_context._code__phrase_role__keyword__void__phrase___phrase_role__special_____phrase___phrase_role__identifier__sp__phrase___code_"><code><phrase
2920         role="keyword">void</phrase> <phrase role="special">*</phrase> <phrase role="identifier">sp</phrase></code></link>
2921       </bridgehead>
2922       <variablelist>
2923         <title></title>
2924         <varlistentry>
2925           <term>Value:</term>
2926           <listitem>
2927             <para>
2928               Pointer to the beginning of the stack.
2929             </para>
2930           </listitem>
2931         </varlistentry>
2932       </variablelist>
2933       <bridgehead renderas="sect4" id="context.stack.stack_context.h1">
2934         <phrase id="context.stack.stack_context._code__phrase_role__identifier__std__phrase__phrase_role__special______phrase__phrase_role__identifier__size_t__phrase___phrase_role__identifier__size__phrase___code_"/><link
2935         linkend="context.stack.stack_context._code__phrase_role__identifier__std__phrase__phrase_role__special______phrase__phrase_role__identifier__size_t__phrase___phrase_role__identifier__size__phrase___code_"><code><phrase
2936         role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase>
2937         <phrase role="identifier">size</phrase></code></link>
2938       </bridgehead>
2939       <variablelist>
2940         <title></title>
2941         <varlistentry>
2942           <term>Value:</term>
2943           <listitem>
2944             <para>
2945               Actual size of the stack.
2946             </para>
2947           </listitem>
2948         </varlistentry>
2949       </variablelist>
2950     </section>
2951     <section id="context.stack.valgrind">
2952       <title><link linkend="context.stack.valgrind">Support for valgrind</link></title>
2953       <para>
2954         Running programs that switch stacks under valgrind causes problems. Property
2955         (b2 command-line) <code><phrase role="identifier">valgrind</phrase><phrase
2956         role="special">=</phrase><phrase role="identifier">on</phrase></code> let
2957         valgrind treat the memory regions as stack space which suppresses the errors.
2958       </para>
2959     </section>
2960   </section>
2961   <section id="context.struct__preallocated_">
2962     <title><link linkend="context.struct__preallocated_">Struct <code><phrase role="identifier">preallocated</phrase></code></link></title>
2963 <programlisting><phrase role="keyword">struct</phrase> <phrase role="identifier">preallocated</phrase> <phrase role="special">{</phrase>
2964     <phrase role="keyword">void</phrase>        <phrase role="special">*</phrase>   <phrase role="identifier">sp</phrase><phrase role="special">;</phrase>
2965     <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase>     <phrase role="identifier">size</phrase><phrase role="special">;</phrase>
2966     <phrase role="identifier">stack_context</phrase>   <phrase role="identifier">sctx</phrase><phrase role="special">;</phrase>
2967
2968     <phrase role="identifier">preallocated</phrase><phrase role="special">(</phrase> <phrase role="keyword">void</phrase> <phrase role="special">*</phrase> <phrase role="identifier">sp</phrase><phrase role="special">,</phrase> <phrase role="identifier">std</phrase><phrase role="special">:</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">size</phrase><phrase role="special">,</phrase> <phrase role="identifier">stack_allocator</phrase> <phrase role="identifier">sctx</phrase><phrase role="special">)</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
2969 <phrase role="special">};</phrase>
2970 </programlisting>
2971     <bridgehead renderas="sect3" id="context.struct__preallocated_.h0">
2972       <phrase id="context.struct__preallocated_.constructor"/><link linkend="context.struct__preallocated_.constructor">Constructor</link>
2973     </bridgehead>
2974 <programlisting><phrase role="identifier">preallocated</phrase><phrase role="special">(</phrase> <phrase role="keyword">void</phrase> <phrase role="special">*</phrase> <phrase role="identifier">sp</phrase><phrase role="special">,</phrase> <phrase role="identifier">std</phrase><phrase role="special">:</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">size</phrase><phrase role="special">,</phrase> <phrase role="identifier">stack_allocator</phrase> <phrase role="identifier">sctx</phrase><phrase role="special">)</phrase> <phrase role="keyword">noexcept</phrase><phrase role="special">;</phrase>
2975 </programlisting>
2976     <variablelist>
2977       <title></title>
2978       <varlistentry>
2979         <term>Effects:</term>
2980         <listitem>
2981           <para>
2982             Creates an object of preallocated.
2983           </para>
2984         </listitem>
2985       </varlistentry>
2986     </variablelist>
2987   </section>
2988   <section id="context.performance">
2989     <title><link linkend="context.performance">Performance</link></title>
2990     <para>
2991       Performance of <emphasis role="bold">Boost.Context</emphasis> was measured
2992       on the platforms shown in the following table. Performance measurements were
2993       taken using <code><phrase role="identifier">rdtsc</phrase></code> and <code><phrase
2994       role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">chrono</phrase><phrase
2995       role="special">::</phrase><phrase role="identifier">high_resolution_clock</phrase></code>,
2996       with overhead corrections, on x86 platforms. In each case, cache warm-up was
2997       accounted for, and the one running thread was pinned to a single CPU. The code
2998       was compiled using the build options, 'variant = release cxxflags = -DBOOST_DISABLE_ASSERTS'.
2999     </para>
3000     <table frame="all" id="context.performance.performance_of_context_switch">
3001       <title>Performance of context switch</title>
3002       <tgroup cols="4">
3003         <thead>
3004           <row>
3005             <entry>
3006               <para>
3007                 Platform
3008               </para>
3009             </entry>
3010             <entry>
3011               <para>
3012                 ucontext_t
3013               </para>
3014             </entry>
3015             <entry>
3016               <para>
3017                 execution_context (v1)
3018               </para>
3019             </entry>
3020             <entry>
3021               <para>
3022                 execution_context (v2)
3023               </para>
3024             </entry>
3025           </row>
3026         </thead>
3027         <tbody>
3028           <row>
3029             <entry>
3030               <para>
3031                 x86_64 <footnote id="context.performance.f0">
3032                 <para>
3033                   Intel Core i7-4770S 3.10GHz
3034                 </para>
3035                 </footnote>
3036               </para>
3037             </entry>
3038             <entry>
3039               <para>
3040                 547 ns / 1433 cycles
3041               </para>
3042             </entry>
3043             <entry>
3044               <para>
3045                 30 ns / 80 cycles
3046               </para>
3047             </entry>
3048             <entry>
3049               <para>
3050                 8 ns / 25 cycles
3051               </para>
3052             </entry>
3053           </row>
3054         </tbody>
3055       </tgroup>
3056     </table>
3057   </section>
3058   <section id="context.architectures">
3059     <title><link linkend="context.architectures">Architectures</link></title>
3060     <para>
3061       <emphasis role="bold">Boost.Context</emphasis> supports following architectures:
3062     </para>
3063     <table frame="all" id="context.architectures.supported_architectures___abi_binary_format__">
3064       <title>Supported architectures (&lt;ABI|binary format&gt;)</title>
3065       <tgroup cols="5">
3066         <thead>
3067           <row>
3068             <entry>
3069               <para>
3070                 Architecture
3071               </para>
3072             </entry>
3073             <entry>
3074               <para>
3075                 LINUX (UNIX)
3076               </para>
3077             </entry>
3078             <entry>
3079               <para>
3080                 Windows
3081               </para>
3082             </entry>
3083             <entry>
3084               <para>
3085                 MacOS X
3086               </para>
3087             </entry>
3088             <entry>
3089               <para>
3090                 iOS
3091               </para>
3092             </entry>
3093           </row>
3094         </thead>
3095         <tbody>
3096           <row>
3097             <entry>
3098               <para>
3099                 arm (aarch32)
3100               </para>
3101             </entry>
3102             <entry>
3103               <para>
3104                 AAPCS|ELF
3105               </para>
3106             </entry>
3107             <entry>
3108               <para>
3109                 AAPCS|PE
3110               </para>
3111             </entry>
3112             <entry>
3113               <para>
3114                 -
3115               </para>
3116             </entry>
3117             <entry>
3118               <para>
3119                 AAPCS|MACH-O
3120               </para>
3121             </entry>
3122           </row>
3123           <row>
3124             <entry>
3125               <para>
3126                 arm (aarch64)
3127               </para>
3128             </entry>
3129             <entry>
3130               <para>
3131                 AAPCS|ELF
3132               </para>
3133             </entry>
3134             <entry>
3135               <para>
3136                 -
3137               </para>
3138             </entry>
3139             <entry>
3140               <para>
3141                 -
3142               </para>
3143             </entry>
3144             <entry>
3145               <para>
3146                 AAPCS|MACH-O
3147               </para>
3148             </entry>
3149           </row>
3150           <row>
3151             <entry>
3152               <para>
3153                 i386
3154               </para>
3155             </entry>
3156             <entry>
3157               <para>
3158                 SYSV|ELF
3159               </para>
3160             </entry>
3161             <entry>
3162               <para>
3163                 MS|PE
3164               </para>
3165             </entry>
3166             <entry>
3167               <para>
3168                 SYSV|MACH-O
3169               </para>
3170             </entry>
3171             <entry>
3172               <para>
3173                 -
3174               </para>
3175             </entry>
3176           </row>
3177           <row>
3178             <entry>
3179               <para>
3180                 mips1
3181               </para>
3182             </entry>
3183             <entry>
3184               <para>
3185                 O32|ELF
3186               </para>
3187             </entry>
3188             <entry>
3189               <para>
3190                 -
3191               </para>
3192             </entry>
3193             <entry>
3194               <para>
3195                 -
3196               </para>
3197             </entry>
3198             <entry>
3199               <para>
3200                 -
3201               </para>
3202             </entry>
3203           </row>
3204           <row>
3205             <entry>
3206               <para>
3207                 ppc32
3208               </para>
3209             </entry>
3210             <entry>
3211               <para>
3212                 SYSV|ELF,XCOFF
3213               </para>
3214             </entry>
3215             <entry>
3216               <para>
3217                 -
3218               </para>
3219             </entry>
3220             <entry>
3221               <para>
3222                 SYSV|MACH-O
3223               </para>
3224             </entry>
3225             <entry>
3226               <para>
3227                 -
3228               </para>
3229             </entry>
3230           </row>
3231           <row>
3232             <entry>
3233               <para>
3234                 ppc64
3235               </para>
3236             </entry>
3237             <entry>
3238               <para>
3239                 SYSV|ELF,XCOFF
3240               </para>
3241             </entry>
3242             <entry>
3243               <para>
3244                 -
3245               </para>
3246             </entry>
3247             <entry>
3248               <para>
3249                 SYSV|MACH-O
3250               </para>
3251             </entry>
3252             <entry>
3253               <para>
3254                 -
3255               </para>
3256             </entry>
3257           </row>
3258           <row>
3259             <entry>
3260               <para>
3261                 sparc
3262               </para>
3263             </entry>
3264             <entry>
3265               <para>
3266                 -
3267               </para>
3268             </entry>
3269             <entry>
3270               <para>
3271                 -
3272               </para>
3273             </entry>
3274             <entry>
3275               <para>
3276                 -
3277               </para>
3278             </entry>
3279             <entry>
3280               <para>
3281                 -
3282               </para>
3283             </entry>
3284           </row>
3285           <row>
3286             <entry>
3287               <para>
3288                 x86_64
3289               </para>
3290             </entry>
3291             <entry>
3292               <para>
3293                 SYSV,X32|ELF
3294               </para>
3295             </entry>
3296             <entry>
3297               <para>
3298                 MS|PE
3299               </para>
3300             </entry>
3301             <entry>
3302               <para>
3303                 SYSV|MACH-O
3304               </para>
3305             </entry>
3306             <entry>
3307               <para>
3308                 -
3309               </para>
3310             </entry>
3311           </row>
3312         </tbody>
3313       </tgroup>
3314     </table>
3315     <section id="context.architectures.crosscompiling">
3316       <title><link linkend="context.architectures.crosscompiling">Cross compiling</link></title>
3317       <para>
3318         Cross compiling the library requires to specify the build properties &lt;architecture&gt;,
3319         &lt;address-model&gt;, &lt;binary-format&gt; and &lt;abi&gt; at b2 command
3320         line.
3321       </para>
3322     </section>
3323   </section>
3324   <section id="context.rationale">
3325     <title><link linkend="context.rationale">Rationale</link></title>
3326     <bridgehead renderas="sect3" id="context.rationale.h0">
3327       <phrase id="context.rationale.no_inline_assembler"/><link linkend="context.rationale.no_inline_assembler">No
3328       inline-assembler</link>
3329     </bridgehead>
3330     <para>
3331       Some newer compiler (for instance MSVC 10 for x86_64 and itanium) do not support
3332       inline assembler. <footnote id="context.rationale.f0">
3333       <para>
3334         <ulink url="http://msdn.microsoft.com/en-us/library/4ks26t93.aspx">MSDN article
3335         'Inline Assembler'</ulink>
3336       </para>
3337       </footnote>. Inlined assembler generates code bloating which is not welcome
3338       on embedded systems.
3339     </para>
3340     <bridgehead renderas="sect3" id="context.rationale.h1">
3341       <phrase id="context.rationale.fcontext_t"/><link linkend="context.rationale.fcontext_t">fcontext_t</link>
3342     </bridgehead>
3343     <para>
3344       <emphasis role="bold">Boost.Context</emphasis> provides the low level API fcontext_t
3345       which is implemented in assembler to provide context swapping operations. fcontext_t
3346       is the part to port to new platforms.
3347     </para>
3348     <note>
3349       <para>
3350         Context switches do not preserve the signal mask on UNIX systems.
3351       </para>
3352     </note>
3353     <para>
3354       <emphasis>fcontext_t</emphasis> is an opaque pointer.
3355     </para>
3356     <section id="context.rationale.other_apis_">
3357       <title><link linkend="context.rationale.other_apis_">Other APIs </link></title>
3358       <bridgehead renderas="sect4" id="context.rationale.other_apis_.h0">
3359         <phrase id="context.rationale.other_apis_.setjmp___longjmp__"/><link linkend="context.rationale.other_apis_.setjmp___longjmp__">setjmp()/longjmp()</link>
3360       </bridgehead>
3361       <para>
3362         C99 defines <code><phrase role="identifier">setjmp</phrase><phrase role="special">()</phrase></code>/<code><phrase
3363         role="identifier">longjmp</phrase><phrase role="special">()</phrase></code>
3364         to provide non-local jumps but it does not require that <emphasis>longjmp()</emphasis>
3365         preserves the current stack frame. Therefore, jumping into a function which
3366         was exited via a call to <emphasis>longjmp()</emphasis> is undefined <footnote
3367         id="context.rationale.other_apis_.f0">
3368         <para>
3369           ISO/IEC 9899:1999, 2005, 7.13.2.1:2
3370         </para>
3371         </footnote>.
3372       </para>
3373       <bridgehead renderas="sect4" id="context.rationale.other_apis_.h1">
3374         <phrase id="context.rationale.other_apis_.ucontext_t"/><link linkend="context.rationale.other_apis_.ucontext_t">ucontext_t</link>
3375       </bridgehead>
3376       <para>
3377         Since POSIX.1-2003 <code><phrase role="identifier">ucontext_t</phrase></code>
3378         is deprecated and was removed in POSIX.1-2008! The function signature of
3379         <code><phrase role="identifier">makecontext</phrase><phrase role="special">()</phrase></code>
3380         is:
3381       </para>
3382 <programlisting><phrase role="keyword">void</phrase> <phrase role="identifier">makecontext</phrase><phrase role="special">(</phrase><phrase role="identifier">ucontext_t</phrase> <phrase role="special">*</phrase><phrase role="identifier">ucp</phrase><phrase role="special">,</phrase> <phrase role="keyword">void</phrase> <phrase role="special">(*</phrase><phrase role="identifier">func</phrase><phrase role="special">)(),</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">argc</phrase><phrase role="special">,</phrase> <phrase role="special">...);</phrase>
3383 </programlisting>
3384       <para>
3385         The third argument of <code><phrase role="identifier">makecontext</phrase><phrase
3386         role="special">()</phrase></code> specifies the number of integer arguments
3387         that follow which will require function pointer cast if <code><phrase role="identifier">func</phrase></code>
3388         will accept those arguments which is undefined in C99 <footnote id="context.rationale.other_apis_.f1">
3389         <para>
3390           ISO/IEC 9899:1999, 2005, J.2
3391         </para>
3392         </footnote>.
3393       </para>
3394       <para>
3395         The arguments in the var-arg list are required to be integers, passing pointers
3396         in var-arg list is not guaranteed to work, especially it will fail for architectures
3397         where pointers are larger than integers.
3398       </para>
3399       <para>
3400         <code><phrase role="identifier">ucontext_t</phrase></code> preserves signal
3401         mask between context switches which involves system calls consuming a lot
3402         of CPU cycles (ucontext_t is slower by perfomance_link[factor 13x] relative
3403         to <code><phrase role="identifier">fcontext_t</phrase></code>).
3404       </para>
3405       <bridgehead renderas="sect4" id="context.rationale.other_apis_.h2">
3406         <phrase id="context.rationale.other_apis_.windows_fibers"/><link linkend="context.rationale.other_apis_.windows_fibers">Windows
3407         fibers</link>
3408       </bridgehead>
3409       <para>
3410         A drawback of Windows Fiber API is that <code><phrase role="identifier">CreateFiber</phrase><phrase
3411         role="special">()</phrase></code> does not accept a pointer to user allocated
3412         stack space preventing the reuse of stacks for other context instances. Because
3413         the Windows Fiber API requires to call <code><phrase role="identifier">ConvertThreadToFiber</phrase><phrase
3414         role="special">()</phrase></code> if <code><phrase role="identifier">SwitchFiber</phrase><phrase
3415         role="special">()</phrase></code> is called for a thread which has not been
3416         converted to a fiber. For the same reason <code><phrase role="identifier">ConvertFiberToThread</phrase><phrase
3417         role="special">()</phrase></code> must be called after return from <code><phrase
3418         role="identifier">SwitchFiber</phrase><phrase role="special">()</phrase></code>
3419         if the thread was forced to be converted to a fiber before (which is inefficient).
3420       </para>
3421 <programlisting><phrase role="keyword">if</phrase> <phrase role="special">(</phrase> <phrase role="special">!</phrase> <phrase role="identifier">is_a_fiber</phrase><phrase role="special">()</phrase> <phrase role="special">)</phrase>
3422 <phrase role="special">{</phrase>
3423     <phrase role="identifier">ConvertThreadToFiber</phrase><phrase role="special">(</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
3424     <phrase role="identifier">SwitchToFiber</phrase><phrase role="special">(</phrase> <phrase role="identifier">ctx</phrase><phrase role="special">);</phrase>
3425     <phrase role="identifier">ConvertFiberToThread</phrase><phrase role="special">();</phrase>
3426 <phrase role="special">}</phrase>
3427 </programlisting>
3428       <para>
3429         If the condition <code><phrase role="identifier">_WIN32_WINNT</phrase> <phrase
3430         role="special">&gt;=</phrase> <phrase role="identifier">_WIN32_WINNT_VISTA</phrase></code>
3431         is met function <code><phrase role="identifier">IsThreadAFiber</phrase><phrase
3432         role="special">()</phrase></code> is provided in order to detect if the current
3433         thread was already converted. Unfortunately Windows XP + SP 2/3 defines
3434         <code><phrase role="identifier">_WIN32_WINNT</phrase> <phrase role="special">&gt;=</phrase>
3435         <phrase role="identifier">_WIN32_WINNT_VISTA</phrase></code> without providing
3436         <code><phrase role="identifier">IsThreadAFiber</phrase><phrase role="special">()</phrase></code>.
3437       </para>
3438     </section>
3439   </section>
3440   <section id="context.reference">
3441     <title><link linkend="context.reference">Reference</link></title>
3442     <bridgehead renderas="sect3" id="context.reference.h0">
3443       <phrase id="context.reference.arm"/><link linkend="context.reference.arm">ARM</link>
3444     </bridgehead>
3445     <itemizedlist>
3446       <listitem>
3447         <simpara>
3448           AAPCS ABI: Procedure Call Standard for the ARM Architecture
3449         </simpara>
3450       </listitem>
3451       <listitem>
3452         <simpara>
3453           AAPCS/LINUX: ARM GNU/Linux Application Binary Interface Supplement
3454         </simpara>
3455       </listitem>
3456     </itemizedlist>
3457     <bridgehead renderas="sect3" id="context.reference.h1">
3458       <phrase id="context.reference.mips"/><link linkend="context.reference.mips">MIPS</link>
3459     </bridgehead>
3460     <itemizedlist>
3461       <listitem>
3462         <simpara>
3463           O32 ABI: SYSTEM V APPLICATION BINARY INTERFACE, MIPS RISC Processor Supplement
3464         </simpara>
3465       </listitem>
3466     </itemizedlist>
3467     <bridgehead renderas="sect3" id="context.reference.h2">
3468       <phrase id="context.reference.powerpc32"/><link linkend="context.reference.powerpc32">PowerPC32</link>
3469     </bridgehead>
3470     <itemizedlist>
3471       <listitem>
3472         <simpara>
3473           SYSV ABI: SYSTEM V APPLICATION BINARY INTERFACE PowerPC Processor Supplement
3474         </simpara>
3475       </listitem>
3476     </itemizedlist>
3477     <bridgehead renderas="sect3" id="context.reference.h3">
3478       <phrase id="context.reference.powerpc64"/><link linkend="context.reference.powerpc64">PowerPC64</link>
3479     </bridgehead>
3480     <itemizedlist>
3481       <listitem>
3482         <simpara>
3483           SYSV ABI: PowerPC User Instruction Set Architecture, Book I
3484         </simpara>
3485       </listitem>
3486     </itemizedlist>
3487     <bridgehead renderas="sect3" id="context.reference.h4">
3488       <phrase id="context.reference.x86_32"/><link linkend="context.reference.x86_32">X86-32</link>
3489     </bridgehead>
3490     <itemizedlist>
3491       <listitem>
3492         <simpara>
3493           SYSV ABI: SYSTEM V APPLICATION BINARY INTERFACE, Intel386TM Architecture
3494           Processor Supplement
3495         </simpara>
3496       </listitem>
3497       <listitem>
3498         <simpara>
3499           MS PE: <ulink url="http://msdn.microsoft.com/en-us/library/k2b2ssfy.aspx">Calling
3500           Conventions</ulink>
3501         </simpara>
3502       </listitem>
3503     </itemizedlist>
3504     <bridgehead renderas="sect3" id="context.reference.h5">
3505       <phrase id="context.reference.x86_64"/><link linkend="context.reference.x86_64">X86-64</link>
3506     </bridgehead>
3507     <itemizedlist>
3508       <listitem>
3509         <simpara>
3510           SYSV ABI: System V Application Binary Interface, AMD64 Architecture Processor
3511           Supplement
3512         </simpara>
3513       </listitem>
3514       <listitem>
3515         <simpara>
3516           MS PE: <ulink url="http://msdn.microsoft.com/en-us/library/7kcdt6fy%28VS.80%29.aspx">x64
3517           Software Conventions</ulink>
3518         </simpara>
3519       </listitem>
3520     </itemizedlist>
3521   </section>
3522   <section id="context.acknowledgements">
3523     <title><link linkend="context.acknowledgements">Acknowledgments</link></title>
3524     <para>
3525       I'd like to thank Adreas Fett, Artyom Beilis, Daniel Larimer, David Deakins,
3526       Evgeny Shapovalov, Fernando Pelliccioni, Giovanni Piero Deretta, Gordon Woodhull,
3527       Helge Bahmann, Holger Grund, Jeffrey Lee Hellrung (Jr.), Keith Jeffery, Martin
3528       Husemann, Phil Endecott, Robert Stewart, Sergey Cheban, Steven Watanabe, Vicente
3529       J. Botet Escriba, Wayne Piekarski.
3530     </para>
3531   </section>
3532 </library>