1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Namespace this_fiber</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. Fiber"> 8<link rel="up" href="../fiber_mgmt.html" title="Fiber management"> 9<link rel="prev" href="id.html" title="Class fiber::id"> 10<link rel="next" href="../scheduling.html" title="Scheduling"> 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="id.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../fiber_mgmt.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="../scheduling.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h3 class="title"> 27<a name="fiber.fiber_mgmt.this_fiber"></a><a class="link" href="this_fiber.html" title="Namespace this_fiber">Namespace this_fiber</a> 28</h3></div></div></div> 29<p> 30 In general, <code class="computeroutput"><span class="identifier">this_fiber</span></code> operations 31 may be called from the <span class="quote">“<span class="quote">main</span>”</span> fiber — the fiber on which function 32 <code class="computeroutput"><span class="identifier">main</span><span class="special">()</span></code> 33 is entered — as well as from an explicitly-launched thread’s thread-function. 34 That is, in many respects the main fiber on each thread can be treated like 35 an explicitly-launched fiber. 36 </p> 37<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> 38<span class="keyword">namespace</span> <span class="identifier">this_fiber</span> <span class="special">{</span> 39 40<span class="identifier">fibers</span><span class="special">::</span><span class="identifier">fiber</span><span class="special">::</span><span class="identifier">id</span> <span class="identifier">get_id</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span> 41<span class="keyword">void</span> <span class="identifier">yield</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span> 42<span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">Clock</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Duration</span> <span class="special">></span> 43<span class="keyword">void</span> <span class="identifier">sleep_until</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">time_point</span><span class="special"><</span> <span class="identifier">Clock</span><span class="special">,</span> <span class="identifier">Duration</span> <span class="special">></span> <span class="keyword">const</span><span class="special">&);</span> 44<span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">Rep</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Period</span> <span class="special">></span> 45<span class="keyword">void</span> <span class="identifier">sleep_for</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration</span><span class="special"><</span> <span class="identifier">Rep</span><span class="special">,</span> <span class="identifier">Period</span> <span class="special">></span> <span class="keyword">const</span><span class="special">&);</span> 46<span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">PROPS</span> <span class="special">></span> 47<span class="identifier">PROPS</span> <span class="special">&</span> <span class="identifier">properties</span><span class="special">();</span> 48 49<span class="special">}}</span> 50</pre> 51<p> 52 </p> 53<h5> 54<a name="this_fiber_get_id_bridgehead"></a> 55 <span class="phrase"><a name="this_fiber_get_id"></a></span> 56 <a class="link" href="this_fiber.html#this_fiber_get_id">Non-member 57 function <code class="computeroutput">this_fiber::get_id()</code></a> 58</h5> 59<p> 60 </p> 61<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">fiber</span><span class="special">/</span><span class="identifier">operations</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 62 63<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> 64<span class="keyword">namespace</span> <span class="identifier">fibers</span> <span class="special">{</span> 65 66<span class="identifier">fiber</span><span class="special">::</span><span class="identifier">id</span> <span class="identifier">get_id</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span> 67 68<span class="special">}}</span> 69</pre> 70<div class="variablelist"> 71<p class="title"><b></b></p> 72<dl class="variablelist"> 73<dt><span class="term">Returns:</span></dt> 74<dd><p> 75 An instance of <a class="link" href="../fiber_mgmt.html#class_fiber_id"><code class="computeroutput"><span class="identifier">fiber</span><span class="special">::</span><span class="identifier">id</span></code></a> that 76 represents the currently executing fiber. 77 </p></dd> 78<dt><span class="term">Throws:</span></dt> 79<dd><p> 80 Nothing. 81 </p></dd> 82</dl> 83</div> 84<p> 85 </p> 86<h5> 87<a name="this_fiber_sleep_until_bridgehead"></a> 88 <span class="phrase"><a name="this_fiber_sleep_until"></a></span> 89 <a class="link" href="this_fiber.html#this_fiber_sleep_until">Non-member 90 function <code class="computeroutput">this_fiber::sleep_until()</code></a> 91</h5> 92<p> 93 </p> 94<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">fiber</span><span class="special">/</span><span class="identifier">operations</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 95 96<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> 97<span class="keyword">namespace</span> <span class="identifier">fibers</span> <span class="special">{</span> 98 99<span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">Clock</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Duration</span> <span class="special">></span> 100<span class="keyword">void</span> <span class="identifier">sleep_until</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">time_point</span><span class="special"><</span> <span class="identifier">Clock</span><span class="special">,</span> <span class="identifier">Duration</span> <span class="special">></span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">abs_time</span><span class="special">);</span> 101 102<span class="special">}}</span> 103</pre> 104<div class="variablelist"> 105<p class="title"><b></b></p> 106<dl class="variablelist"> 107<dt><span class="term">Effects:</span></dt> 108<dd><p> 109 Suspends the current fiber until the time point specified by <code class="computeroutput"><span class="identifier">abs_time</span></code> has been reached. 110 </p></dd> 111<dt><span class="term">Throws:</span></dt> 112<dd><p> 113 timeout-related exceptions. 114 </p></dd> 115<dt><span class="term">Note:</span></dt> 116<dd><p> 117 The current fiber will not resume before <code class="computeroutput"><span class="identifier">abs_time</span></code>, 118 but there are no guarantees about how soon after <code class="computeroutput"><span class="identifier">abs_time</span></code> 119 it might resume. 120 </p></dd> 121<dt><span class="term">Note:</span></dt> 122<dd><p> 123 <span class="quote">“<span class="quote">timeout-related exceptions</span>”</span> are as defined in the C++ 124 Standard, section <span class="bold"><strong>30.2.4 Timing specifications 125 [thread.req.timing]</strong></span>: <span class="quote">“<span class="quote">A function that takes an argument 126 which specifies a timeout will throw if, during its execution, a clock, 127 time point, or time duration throws an exception. Such exceptions are 128 referred to as <span class="emphasis"><em>timeout-related exceptions.</em></span></span>”</span> 129 </p></dd> 130</dl> 131</div> 132<p> 133 </p> 134<h5> 135<a name="this_fiber_sleep_for_bridgehead"></a> 136 <span class="phrase"><a name="this_fiber_sleep_for"></a></span> 137 <a class="link" href="this_fiber.html#this_fiber_sleep_for">Non-member 138 function <code class="computeroutput">this_fiber::sleep_for()</code></a> 139</h5> 140<p> 141 </p> 142<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">fiber</span><span class="special">/</span><span class="identifier">operations</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 143 144<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> 145<span class="keyword">namespace</span> <span class="identifier">fibers</span> <span class="special">{</span> 146 147<span class="keyword">template</span><span class="special"><</span> <span class="keyword">class</span> <span class="identifier">Rep</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Period</span> <span class="special">></span> 148<span class="keyword">void</span> <span class="identifier">sleep_for</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration</span><span class="special"><</span> <span class="identifier">Rep</span><span class="special">,</span> <span class="identifier">Period</span> <span class="special">></span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">rel_time</span><span class="special">);</span> 149 150<span class="special">}}</span> 151</pre> 152<div class="variablelist"> 153<p class="title"><b></b></p> 154<dl class="variablelist"> 155<dt><span class="term">Effects:</span></dt> 156<dd><p> 157 Suspends the current fiber until the time duration specified by <code class="computeroutput"><span class="identifier">rel_time</span></code> has elapsed. 158 </p></dd> 159<dt><span class="term">Throws:</span></dt> 160<dd><p> 161 timeout-related exceptions. 162 </p></dd> 163<dt><span class="term">Note:</span></dt> 164<dd><p> 165 The current fiber will not resume before <code class="computeroutput"><span class="identifier">rel_time</span></code> 166 has elapsed, but there are no guarantees about how soon after that 167 it might resume. 168 </p></dd> 169</dl> 170</div> 171<p> 172 </p> 173<h5> 174<a name="this_fiber_yield_bridgehead"></a> 175 <span class="phrase"><a name="this_fiber_yield"></a></span> 176 <a class="link" href="this_fiber.html#this_fiber_yield">Non-member function 177 <code class="computeroutput">this_fiber::yield()</code></a> 178</h5> 179<p> 180 </p> 181<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">fiber</span><span class="special">/</span><span class="identifier">operations</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 182 183<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> 184<span class="keyword">namespace</span> <span class="identifier">fibers</span> <span class="special">{</span> 185 186<span class="keyword">void</span> <span class="identifier">yield</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span> 187 188<span class="special">}}</span> 189</pre> 190<div class="variablelist"> 191<p class="title"><b></b></p> 192<dl class="variablelist"> 193<dt><span class="term">Effects:</span></dt> 194<dd><p> 195 Relinquishes execution control, allowing other fibers to run. 196 </p></dd> 197<dt><span class="term">Throws:</span></dt> 198<dd><p> 199 Nothing. 200 </p></dd> 201<dt><span class="term">Note:</span></dt> 202<dd><p> 203 A fiber that calls <code class="computeroutput"><span class="identifier">yield</span><span class="special">()</span></code> is not suspended: it is immediately 204 passed to the scheduler as ready to run. 205 </p></dd> 206</dl> 207</div> 208<p> 209 </p> 210<h5> 211<a name="this_fiber_properties_bridgehead"></a> 212 <span class="phrase"><a name="this_fiber_properties"></a></span> 213 <a class="link" href="this_fiber.html#this_fiber_properties">Non-member 214 function <code class="computeroutput">this_fiber::properties()</code></a> 215</h5> 216<p> 217 </p> 218<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">fiber</span><span class="special">/</span><span class="identifier">operations</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 219 220<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> 221<span class="keyword">namespace</span> <span class="identifier">fibers</span> <span class="special">{</span> 222 223<span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">PROPS</span> <span class="special">></span> 224<span class="identifier">PROPS</span> <span class="special">&</span> <span class="identifier">properties</span><span class="special">();</span> 225 226<span class="special">}}</span> 227</pre> 228<div class="variablelist"> 229<p class="title"><b></b></p> 230<dl class="variablelist"> 231<dt><span class="term">Preconditions:</span></dt> 232<dd><p> 233 <a class="link" href="fiber.html#use_scheduling_algorithm"><code class="computeroutput">use_scheduling_algorithm()</code></a> has been called from 234 this thread with a subclass of <a class="link" href="../scheduling.html#class_algorithm_with_properties"><code class="computeroutput">algorithm_with_properties<></code></a> with 235 the same template argument <code class="computeroutput"><span class="identifier">PROPS</span></code>. 236 </p></dd> 237<dt><span class="term">Returns:</span></dt> 238<dd><p> 239 a reference to the scheduler properties instance for the currently 240 running fiber. 241 </p></dd> 242<dt><span class="term">Throws:</span></dt> 243<dd><p> 244 <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">bad_cast</span></code> if <code class="computeroutput"><span class="identifier">use_scheduling_algorithm</span><span class="special">()</span></code> was called with an <code class="computeroutput"><span class="identifier">algorithm_with_properties</span></code> subclass 245 with some other template parameter than <code class="computeroutput"><span class="identifier">PROPS</span></code>. 246 </p></dd> 247<dt><span class="term">Note:</span></dt> 248<dd><p> 249 <a class="link" href="../scheduling.html#class_algorithm_with_properties"><code class="computeroutput">algorithm_with_properties<></code></a> provides 250 a way for a user-coded scheduler to associate extended properties, 251 such as priority, with a fiber instance. This function allows access 252 to those user-provided properties. 253 </p></dd> 254<dt><span class="term">Note:</span></dt> 255<dd><p> 256 The first time this function is called from the main fiber of a thread, 257 it may internally yield, permitting other fibers to run. 258 </p></dd> 259<dt><span class="term">See also:</span></dt> 260<dd><p> 261 <a class="link" href="../custom.html#custom">Customization</a> 262 </p></dd> 263</dl> 264</div> 265</div> 266<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 267<td align="left"></td> 268<td align="right"><div class="copyright-footer">Copyright © 2013 Oliver Kowalke<p> 269 Distributed under the Boost Software License, Version 1.0. (See accompanying 270 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>) 271 </p> 272</div></td> 273</tr></table> 274<hr> 275<div class="spirit-nav"> 276<a accesskey="p" href="id.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../fiber_mgmt.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="../scheduling.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 277</div> 278</body> 279</html> 280