1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 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.79.1"> 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 execution context represents a specific point 35 in the application's execution path. This is useful for building higher-level 36 abstractions, like <span class="emphasis"><em>coroutines</em></span>, <span class="emphasis"><em>cooperative threads 37 (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 <a class="link" href="cc.html#cc"><span class="emphasis"><em>callcc()</em></span></a>/<a class="link" href="cc.html#cc"><span class="emphasis"><em>continuation</em></span></a> 42 provides the means to suspend the current execution path and to transfer execution 43 control, thereby permitting another context to run on the current thread. This 44 state full transfer mechanism enables a context to suspend execution from within 45 nested functions and, later, to resume from where it was suspended. While the 46 execution path represented by a <a class="link" href="cc.html#cc"><span class="emphasis"><em>continuation</em></span></a> 47 only runs on a single thread, it can be migrated to another thread at any given 48 time. 49 </p> 50<p> 51 A <a href="http://en.wikipedia.org/wiki/Context_switch" target="_top">context switch</a> 52 between threads requires system calls (involving the OS kernel), which can 53 cost more than thousand CPU cycles on x86 CPUs. By contrast, transferring control 54 vias <a class="link" href="cc.html#cc"><span class="emphasis"><em>callcc()</em></span></a>/<a class="link" href="cc.html#cc"><span class="emphasis"><em>continuation</em></span></a> 55 requires only few CPU cycles because it does not involve system calls as it 56 is done within a single thread. 57 </p> 58<p> 59 All functions and classes are contained in the namespace <span class="emphasis"><em>boost::context</em></span>. 60 </p> 61<div class="note"><table border="0" summary="Note"> 62<tr> 63<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../doc/src/images/note.png"></td> 64<th align="left">Note</th> 65</tr> 66<tr><td align="left" valign="top"><p> 67 This library requires C++11! 68 </p></td></tr> 69</table></div> 70<div class="important"><table border="0" summary="Important"> 71<tr> 72<td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../../../doc/src/images/important.png"></td> 73<th align="left">Important</th> 74</tr> 75<tr><td align="left" valign="top"><p> 76 Windows using fcontext_t: turn off global program optimization (/GL) and 77 change /EHsc (compiler assumes that functions declared as extern "C" 78 never throw a C++ exception) to /EHs (tells compiler assumes that functions 79 declared as extern "C" may throw an exception). 80 </p></td></tr> 81</table></div> 82</div> 83<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 84<td align="left"></td> 85<td align="right"><div class="copyright-footer">Copyright © 2014 Oliver Kowalke<p> 86 Distributed under the Boost Software License, Version 1.0. (See accompanying 87 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>) 88 </p> 89</div></td> 90</tr></table> 91<hr> 92<div class="spirit-nav"> 93<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> 94</div> 95</body> 96</html> 97