]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fiber/doc/html/fiber/rationale.html
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / fiber / doc / html / fiber / rationale.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Rationale</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&#160;1.&#160;Fiber">
8 <link rel="up" href="../index.html" title="Chapter&#160;1.&#160;Fiber">
9 <link rel="prev" href="custom.html" title="Customization">
10 <link rel="next" href="acknowledgements.html" title="Acknowledgments">
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="custom.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="acknowledgements.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="fiber.rationale"></a><a class="link" href="rationale.html" title="Rationale">Rationale</a>
28 </h2></div></div></div>
29 <h4>
30 <a name="fiber.rationale.h0"></a>
31 <span><a name="fiber.rationale.distinction_between_coroutines_and_fibers"></a></span><a class="link" href="rationale.html#fiber.rationale.distinction_between_coroutines_and_fibers">distinction
32 between coroutines and fibers</a>
33 </h4>
34 <p>
35 The fiber library extends the coroutine library by adding a scheduler and synchronization
36 mechanisms.
37 </p>
38 <div class="itemizedlist"><ul class="itemizedlist" type="disc">
39 <li class="listitem">
40 a coroutine yields
41 </li>
42 <li class="listitem">
43 a fiber blocks
44 </li>
45 </ul></div>
46 <p>
47 When a coroutine yields, it passes control directly to its caller (or, in the
48 case of symmetric coroutines, a designated other coroutine). When a fiber blocks,
49 it implicitly passes control to the fiber scheduler. Coroutines have no scheduler
50 because they need no scheduler.<sup>[<a name="fiber.rationale.f0" href="#ftn.fiber.rationale.f0" class="footnote">10</a>]</sup>.
51 </p>
52 <h4>
53 <a name="fiber.rationale.h1"></a>
54 <span><a name="fiber.rationale.what_about_transactional_memory"></a></span><a class="link" href="rationale.html#fiber.rationale.what_about_transactional_memory">what
55 about transactional memory</a>
56 </h4>
57 <p>
58 GCC supports transactional memory since version 4.7. Unfortunately tests show
59 that transactional memory is slower (ca. 4x) than spinlocks using atomics.
60 Once transactional memory is improved (supporting hybrid tm), spinlocks will
61 be replaced by __transaction_atomic{} statements surrounding the critical sections.
62 </p>
63 <h4>
64 <a name="fiber.rationale.h2"></a>
65 <span><a name="fiber.rationale.synchronization_between_fibers_running_in_different_threads"></a></span><a class="link" href="rationale.html#fiber.rationale.synchronization_between_fibers_running_in_different_threads">synchronization
66 between fibers running in different threads</a>
67 </h4>
68 <p>
69 Synchronization classes from <a href="http://www.boost.org/doc/libs/release/libs/thread/index.html" target="_top">Boost.Thread</a>
70 block the entire thread. In contrast, the synchronization classes from <span class="bold"><strong>Boost.Fiber</strong></span> block only specific fibers, so that the
71 scheduler can still keep the thread busy running other fibers in the meantime.
72 The synchronization classes from <span class="bold"><strong>Boost.Fiber</strong></span>
73 are designed to be thread-safe, i.e. it is possible to synchronize fibers running
74 in different threads as well as fibers running in the same thread. (However,
75 there is a build option to disable cross-thread fiber synchronization support;
76 see <a class="link" href="overview.html#cross_thread_sync">this description</a>.)
77 </p>
78 <a name="spurious_wakeup"></a><h4>
79 <a name="fiber.rationale.h3"></a>
80 <span><a name="fiber.rationale.spurious_wakeup"></a></span><a class="link" href="rationale.html#fiber.rationale.spurious_wakeup">spurious
81 wakeup</a>
82 </h4>
83 <p>
84 Spurious wakeup can happen when using <a href="http://en.cppreference.com/w/cpp/thread/condition_variable" target="_top"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">condition_variable</span></code></a>:
85 the condition variable appears to be have been signaled while the awaited condition
86 may still be false. Spurious wakeup can happen repeatedly and is caused on
87 some multiprocessor systems where making <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">condition_variable</span></code>
88 wakeup completely predictable would slow down all <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">condition_variable</span></code>
89 operations.<sup>[<a name="fiber.rationale.f1" href="#ftn.fiber.rationale.f1" class="footnote">11</a>]</sup>
90 </p>
91 <p>
92 <a class="link" href="synchronization/conditions.html#class_condition_variable"><code class="computeroutput">condition_variable</code></a> is not subject to spurious wakeup.
93 Nonetheless it is prudent to test the business-logic condition in a <code class="computeroutput"><span class="identifier">wait</span><span class="special">()</span></code> loop
94 &#8212; or, equivalently, use one of the <code class="computeroutput"><span class="identifier">wait</span><span class="special">(</span> <span class="identifier">lock</span><span class="special">,</span>
95 <span class="identifier">predicate</span> <span class="special">)</span></code>
96 overloads.
97 </p>
98 <p>
99 See also <a class="link" href="synchronization/conditions.html#condition_variable_spurious_wakeups">No Spurious Wakeups</a>.
100 </p>
101 <h4>
102 <a name="fiber.rationale.h4"></a>
103 <span><a name="fiber.rationale.migrating_fibers_between_threads"></a></span><a class="link" href="rationale.html#fiber.rationale.migrating_fibers_between_threads">migrating
104 fibers between threads</a>
105 </h4>
106 <p>
107 Support for migrating fibers between threads has been integrated. The user-defined
108 scheduler must call <a class="link" href="scheduling.html#context_detach"><code class="computeroutput">context::detach()</code></a> on a fiber-context on the
109 source thread and <a class="link" href="scheduling.html#context_attach"><code class="computeroutput">context::attach()</code></a> on the destination thread,
110 passing the fiber-context to migrate. (For more information about custom schedulers,
111 see <a class="link" href="custom.html#custom">Customization</a>.) Examples <code class="computeroutput"><span class="identifier">work_sharing</span></code>
112 and <code class="computeroutput"><span class="identifier">work_stealing</span></code> in directory
113 <code class="computeroutput"><span class="identifier">examples</span></code> might be used as a
114 blueprint.
115 </p>
116 <p>
117 See also <a class="link" href="migration.html#migration">Migrating fibers between threads</a>.
118 </p>
119 <h4>
120 <a name="fiber.rationale.h5"></a>
121 <span><a name="fiber.rationale.support_for_boost_asio"></a></span><a class="link" href="rationale.html#fiber.rationale.support_for_boost_asio">support
122 for Boost.Asio</a>
123 </h4>
124 <p>
125 Support for <a href="http://www.boost.org/doc/libs/release/libs/asio/index.html" target="_top">Boost.Asio</a>&#8217;s
126 <span class="emphasis"><em>async-result</em></span> is not part of the official API. However,
127 to integrate with a <a href="http://www.boost.org/doc/libs/release/doc/html/boost_asio/reference/io_service.html" target="_top"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">asio</span><span class="special">::</span><span class="identifier">io_service</span></code></a>,
128 see <a class="link" href="integration.html#integration">Sharing a Thread with Another Main Loop</a>.
129 To interface smoothly with an arbitrary Asio async I/O operation, see <a class="link" href="callbacks/then_there_s____boost_asio__.html#callbacks_asio">Then There&#8217;s <a href="http://www.boost.org/doc/libs/release/libs/asio/index.html" target="_top">Boost.Asio</a></a>.
130 </p>
131 <h4>
132 <a name="fiber.rationale.h6"></a>
133 <span><a name="fiber.rationale.tested_compilers"></a></span><a class="link" href="rationale.html#fiber.rationale.tested_compilers">tested
134 compilers</a>
135 </h4>
136 <p>
137 The library was tested with GCC-5.1.1, Clang-3.6.0 and MSVC-14.0 in c++11-mode.
138 </p>
139 <h4>
140 <a name="fiber.rationale.h7"></a>
141 <span><a name="fiber.rationale.supported_architectures"></a></span><a class="link" href="rationale.html#fiber.rationale.supported_architectures">supported
142 architectures</a>
143 </h4>
144 <p>
145 <span class="bold"><strong>Boost.Fiber</strong></span> depends on <a href="http://www.boost.org/doc/libs/release/libs/context/index.html" target="_top">Boost.Context</a>
146 - the list of supported architectures can be found <a href="http://www.boost.org/doc/libs/release/libs/context/doc/html/context/architectures.html" target="_top">here</a>.
147 </p>
148 <div class="footnotes">
149 <br><hr width="100" align="left">
150 <div class="footnote"><p><sup>[<a name="ftn.fiber.rationale.f0" href="#fiber.rationale.f0" class="para">10</a>] </sup>
151 <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4024.pdf" target="_top">'N4024:
152 Distinguishing coroutines and fibers'</a>
153 </p></div>
154 <div class="footnote"><p><sup>[<a name="ftn.fiber.rationale.f1" href="#fiber.rationale.f1" class="para">11</a>] </sup>
155 David R. Butenhof <span class="quote">&#8220;<span class="quote">Programming with POSIX Threads</span>&#8221;</span>
156 </p></div>
157 </div>
158 </div>
159 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
160 <td align="left"></td>
161 <td align="right"><div class="copyright-footer">Copyright &#169; 2013 Oliver Kowalke<p>
162 Distributed under the Boost Software License, Version 1.0. (See accompanying
163 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>)
164 </p>
165 </div></td>
166 </tr></table>
167 <hr>
168 <div class="spirit-nav">
169 <a accesskey="p" href="custom.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="acknowledgements.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
170 </div>
171 </body>
172 </html>