]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | <html> |
2 | <head> | |
3 | <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> | |
4 | <title>Overview</title> | |
5 | <link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css"> | |
6 | <meta name="generator" content="DocBook XSL Stylesheets V1.75.2"> | |
7 | <link rel="home" href="../index.html" title="Chapter 1. Context"> | |
8 | <link rel="up" href="../index.html" title="Chapter 1. Context"> | |
9 | <link rel="prev" href="../index.html" title="Chapter 1. Context"> | |
10 | <link rel="next" href="requirements.html" title="Requirements"> | |
11 | </head> | |
12 | <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> | |
13 | <table cellpadding="2" width="100%"><tr> | |
14 | <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td> | |
15 | <td align="center"><a href="../../../../../index.html">Home</a></td> | |
16 | <td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td> | |
17 | <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> | |
18 | <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> | |
19 | <td align="center"><a href="../../../../../more/index.htm">More</a></td> | |
20 | </tr></table> | |
21 | <hr> | |
22 | <div class="spirit-nav"> | |
23 | <a accesskey="p" href="../index.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="requirements.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a> | |
24 | </div> | |
25 | <div class="section"> | |
26 | <div class="titlepage"><div><div><h2 class="title" style="clear: both"> | |
27 | <a name="context.overview"></a><a class="link" href="overview.html" title="Overview">Overview</a> | |
28 | </h2></div></div></div> | |
29 | <p> | |
30 | <span class="bold"><strong>Boost.Context</strong></span> is a foundational library that | |
31 | provides a sort of cooperative multitasking on a single thread. By providing | |
32 | an abstraction of the current execution state in the current thread, including | |
33 | the stack (with local variables) and stack pointer, all registers and CPU flags, | |
34 | and the instruction pointer, a <span class="emphasis"><em>execution_context</em></span> represents | |
35 | a specific point in the application's execution path. This is useful for building | |
36 | higher-level abstractions, like <span class="emphasis"><em>coroutines</em></span>, <span class="emphasis"><em>cooperative | |
37 | threads (userland threads)</em></span> or an equivalent to <a href="http://msdn.microsoft.com/en-us/library/9k7k7cf0%28v=vs.80%29.aspx" target="_top">C# | |
38 | keyword <span class="emphasis"><em>yield</em></span></a> in C++. | |
39 | </p> | |
40 | <p> | |
41 | <span class="emphasis"><em>execution_context</em></span> provides the means to suspend the current | |
42 | execution path and to transfer execution control, thereby permitting another | |
43 | context to run on the current thread. This state full transfer mechanism enables | |
44 | a context to suspend execution from within nested functions and, later, to | |
45 | resume from where it was suspended. While the execution path represented by | |
46 | a <span class="emphasis"><em>execution_context</em></span> only runs on a single thread, it can | |
47 | be migrated to another thread at any given time. | |
48 | </p> | |
49 | <p> | |
50 | A context switch between threads requires system calls (involving the OS kernel), | |
51 | which can cost more than thousand CPU cycles on x86 CPUs. By contrast, transferring | |
52 | control among them requires only few CPU cycles because it does not involve | |
53 | system calls as it is done within a single thread. | |
54 | </p> | |
55 | <p> | |
56 | In order to use the classes and functions described here, you can either include | |
57 | the specific headers specified by the descriptions of each class or function, | |
58 | or include the master library header: | |
59 | </p> | |
60 | <pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">context</span><span class="special">/</span><span class="identifier">all</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> | |
61 | </pre> | |
62 | <p> | |
63 | which includes all the other headers in turn. | |
64 | </p> | |
65 | <p> | |
66 | All functions and classes are contained in the namespace <span class="emphasis"><em>boost::context</em></span>. | |
67 | </p> | |
68 | <div class="important"><table border="0" summary="Important"> | |
69 | <tr> | |
70 | <td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../../../doc/src/images/important.png"></td> | |
71 | <th align="left">Important</th> | |
72 | </tr> | |
73 | <tr><td align="left" valign="top"><p> | |
74 | <span class="emphasis"><em>execution_context</em></span> requires C++11! | |
75 | </p></td></tr> | |
76 | </table></div> | |
77 | </div> | |
78 | <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> | |
79 | <td align="left"></td> | |
80 | <td align="right"><div class="copyright-footer">Copyright © 2014 Oliver Kowalke<p> | |
81 | Distributed under the Boost Software License, Version 1.0. (See accompanying | |
82 | file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) | |
83 | </p> | |
84 | </div></td> | |
85 | </tr></table> | |
86 | <hr> | |
87 | <div class="spirit-nav"> | |
88 | <a accesskey="p" href="../index.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="requirements.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a> | |
89 | </div> | |
90 | </body> | |
91 | </html> |