1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Buffered Channel</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="../channels.html" title="Channels"> 9<link rel="prev" href="../channels.html" title="Channels"> 10<link rel="next" href="unbuffered_channel.html" title="Unbuffered Channel"> 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="../channels.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../channels.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="unbuffered_channel.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h4 class="title"> 27<a name="fiber.synchronization.channels.buffered_channel"></a><a class="link" href="buffered_channel.html" title="Buffered Channel">Buffered 28 Channel</a> 29</h4></div></div></div> 30<p> 31 <span class="bold"><strong>Boost.Fiber</strong></span> provides a bounded, buffered 32 channel (MPMC queue) suitable to synchonize fibers (running on same or 33 different threads) via asynchronouss message passing. 34 </p> 35<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">fibers</span><span class="special">::</span><span class="identifier">buffered_channel</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="identifier">channel_t</span><span class="special">;</span> 36 37<span class="keyword">void</span> <span class="identifier">send</span><span class="special">(</span> <span class="identifier">channel_t</span> <span class="special">&</span> <span class="identifier">chan</span><span class="special">)</span> <span class="special">{</span> 38 <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="number">5</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> <span class="special">{</span> 39 <span class="identifier">chan</span><span class="special">.</span><span class="identifier">push</span><span class="special">(</span> <span class="identifier">i</span><span class="special">);</span> 40 <span class="special">}</span> 41 <span class="identifier">chan</span><span class="special">.</span><span class="identifier">close</span><span class="special">();</span> 42<span class="special">}</span> 43 44<span class="keyword">void</span> <span class="identifier">recv</span><span class="special">(</span> <span class="identifier">channel_t</span> <span class="special">&</span> <span class="identifier">chan</span><span class="special">)</span> <span class="special">{</span> 45 <span class="keyword">int</span> <span class="identifier">i</span><span class="special">;</span> 46 <span class="keyword">while</span> <span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">fibers</span><span class="special">::</span><span class="identifier">channel_op_status</span><span class="special">::</span><span class="identifier">success</span> <span class="special">==</span> <span class="identifier">chan</span><span class="special">.</span><span class="identifier">pop</span><span class="special">(</span><span class="identifier">i</span><span class="special">)</span> <span class="special">)</span> <span class="special">{</span> 47 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"received "</span> <span class="special"><<</span> <span class="identifier">i</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 48 <span class="special">}</span> 49<span class="special">}</span> 50 51<span class="identifier">channel_t</span> <span class="identifier">chan</span><span class="special">{</span> <span class="number">2</span> <span class="special">};</span> 52<span class="identifier">boost</span><span class="special">::</span><span class="identifier">fibers</span><span class="special">::</span><span class="identifier">fiber</span> <span class="identifier">f1</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span> <span class="identifier">send</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span> <span class="identifier">chan</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span> 53<span class="identifier">boost</span><span class="special">::</span><span class="identifier">fibers</span><span class="special">::</span><span class="identifier">fiber</span> <span class="identifier">f2</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span> <span class="identifier">recv</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span> <span class="identifier">chan</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span> 54 55<span class="identifier">f1</span><span class="special">.</span><span class="identifier">join</span><span class="special">();</span> 56<span class="identifier">f2</span><span class="special">.</span><span class="identifier">join</span><span class="special">();</span> 57</pre> 58<p> 59 Class <code class="computeroutput"><span class="identifier">buffered_channel</span></code> 60 supports range-for syntax: 61 </p> 62<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">fibers</span><span class="special">::</span><span class="identifier">buffered_channel</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="identifier">channel_t</span><span class="special">;</span> 63 64<span class="keyword">void</span> <span class="identifier">foo</span><span class="special">(</span> <span class="identifier">channel_t</span> <span class="special">&</span> <span class="identifier">chan</span><span class="special">)</span> <span class="special">{</span> 65 <span class="identifier">chan</span><span class="special">.</span><span class="identifier">push</span><span class="special">(</span> <span class="number">1</span><span class="special">);</span> 66 <span class="identifier">chan</span><span class="special">.</span><span class="identifier">push</span><span class="special">(</span> <span class="number">1</span><span class="special">);</span> 67 <span class="identifier">chan</span><span class="special">.</span><span class="identifier">push</span><span class="special">(</span> <span class="number">2</span><span class="special">);</span> 68 <span class="identifier">chan</span><span class="special">.</span><span class="identifier">push</span><span class="special">(</span> <span class="number">3</span><span class="special">);</span> 69 <span class="identifier">chan</span><span class="special">.</span><span class="identifier">push</span><span class="special">(</span> <span class="number">5</span><span class="special">);</span> 70 <span class="identifier">chan</span><span class="special">.</span><span class="identifier">push</span><span class="special">(</span> <span class="number">8</span><span class="special">);</span> 71 <span class="identifier">chan</span><span class="special">.</span><span class="identifier">push</span><span class="special">(</span> <span class="number">12</span><span class="special">);</span> 72 <span class="identifier">chan</span><span class="special">.</span><span class="identifier">close</span><span class="special">();</span> 73<span class="special">}</span> 74 75<span class="keyword">void</span> <span class="identifier">bar</span><span class="special">(</span> <span class="identifier">channel_t</span> <span class="special">&</span> <span class="identifier">chan</span><span class="special">)</span> <span class="special">{</span> 76 <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">value</span> <span class="special">:</span> <span class="identifier">chan</span><span class="special">)</span> <span class="special">{</span> 77 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">value</span> <span class="special"><<</span> <span class="string">" "</span><span class="special">;</span> 78 <span class="special">}</span> 79 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 80<span class="special">}</span> 81</pre> 82<p> 83 </p> 84<h5> 85<a name="class_buffered_channel_bridgehead"></a> 86 <span class="phrase"><a name="class_buffered_channel"></a></span> 87 <a class="link" href="buffered_channel.html#class_buffered_channel">Template 88 <code class="computeroutput">buffered_channel<></code></a> 89</h5> 90<p> 91 </p> 92<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">buffered_channel</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 93 94<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> 95<span class="keyword">namespace</span> <span class="identifier">fibers</span> <span class="special">{</span> 96 97<span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">></span> 98<span class="keyword">class</span> <span class="identifier">buffered_channel</span> <span class="special">{</span> 99<span class="keyword">public</span><span class="special">:</span> 100 <span class="keyword">typedef</span> <span class="identifier">T</span> <span class="identifier">value_type</span><span class="special">;</span> 101 102 <span class="keyword">class</span> <span class="identifier">iterator</span><span class="special">;</span> 103 104 <span class="keyword">explicit</span> <span class="identifier">buffered_channel</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">capacity</span><span class="special">);</span> 105 106 <span class="identifier">buffered_channel</span><span class="special">(</span> <span class="identifier">buffered_channel</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">other</span><span class="special">)</span> <span class="special">=</span> <span class="keyword">delete</span><span class="special">;</span> 107 <span class="identifier">buffered_channel</span> <span class="special">&</span> <span class="keyword">operator</span><span class="special">=(</span> <span class="identifier">buffered_channel</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">other</span><span class="special">)</span> <span class="special">=</span> <span class="keyword">delete</span><span class="special">;</span> 108 109 <span class="keyword">void</span> <span class="identifier">close</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span> 110 111 <span class="identifier">channel_op_status</span> <span class="identifier">push</span><span class="special">(</span> <span class="identifier">value_type</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">va</span><span class="special">);</span> 112 <span class="identifier">channel_op_status</span> <span class="identifier">push</span><span class="special">(</span> <span class="identifier">value_type</span> <span class="special">&&</span> <span class="identifier">va</span><span class="special">);</span> 113 <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> 114 <span class="identifier">channel_op_status</span> <span class="identifier">push_wait_for</span><span class="special">(</span> 115 <span class="identifier">value_type</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">va</span><span class="special">,</span> 116 <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">timeout_duration</span><span class="special">);</span> 117 <span class="identifier">channel_op_status</span> <span class="identifier">push_wait_for</span><span class="special">(</span> <span class="identifier">value_type</span> <span class="special">&&</span> <span class="identifier">va</span><span class="special">,</span> 118 <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">timeout_duration</span><span class="special">);</span> 119 <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> 120 <span class="identifier">channel_op_status</span> <span class="identifier">push_wait_until</span><span class="special">(</span> 121 <span class="identifier">value_type</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">va</span><span class="special">,</span> 122 <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">timeout_time</span><span class="special">);</span> 123 <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> 124 <span class="identifier">channel_op_status</span> <span class="identifier">push_wait_until</span><span class="special">(</span> 125 <span class="identifier">value_type</span> <span class="special">&&</span> <span class="identifier">va</span><span class="special">,</span> 126 <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">timeout_time</span><span class="special">);</span> 127 <span class="identifier">channel_op_status</span> <span class="identifier">try_push</span><span class="special">(</span> <span class="identifier">value_type</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">va</span><span class="special">);</span> 128 <span class="identifier">channel_op_status</span> <span class="identifier">try_push</span><span class="special">(</span> <span class="identifier">value_type</span> <span class="special">&&</span> <span class="identifier">va</span><span class="special">);</span> 129 130 <span class="identifier">channel_op_status</span> <span class="identifier">pop</span><span class="special">(</span> <span class="identifier">value_type</span> <span class="special">&</span> <span class="identifier">va</span><span class="special">);</span> 131 <span class="identifier">value_type</span> <span class="identifier">value_pop</span><span class="special">();</span> 132 <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> 133 <span class="identifier">channel_op_status</span> <span class="identifier">pop_wait_for</span><span class="special">(</span> 134 <span class="identifier">value_type</span> <span class="special">&</span> <span class="identifier">va</span><span class="special">,</span> 135 <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">timeout_duration</span><span class="special">);</span> 136 <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> 137 <span class="identifier">channel_op_status</span> <span class="identifier">pop_wait_until</span><span class="special">(</span> 138 <span class="identifier">value_type</span> <span class="special">&</span> <span class="identifier">va</span><span class="special">,</span> 139 <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">timeout_time</span><span class="special">);</span> 140 <span class="identifier">channel_op_status</span> <span class="identifier">try_pop</span><span class="special">(</span> <span class="identifier">value_type</span> <span class="special">&</span> <span class="identifier">va</span><span class="special">);</span> 141<span class="special">};</span> 142 143<span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">></span> 144<span class="identifier">buffered_channel</span><span class="special"><</span> <span class="identifier">T</span> <span class="special">>::</span><span class="identifier">iterator</span> <span class="identifier">begin</span><span class="special">(</span> <span class="identifier">buffered_channel</span><span class="special"><</span> <span class="identifier">T</span> <span class="special">></span> <span class="special">&</span> <span class="identifier">chan</span><span class="special">);</span> 145 146<span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">></span> 147<span class="identifier">buffered_channel</span><span class="special"><</span> <span class="identifier">T</span> <span class="special">>::</span><span class="identifier">iterator</span> <span class="identifier">end</span><span class="special">(</span> <span class="identifier">buffered_channel</span><span class="special"><</span> <span class="identifier">T</span> <span class="special">></span> <span class="special">&</span> <span class="identifier">chan</span><span class="special">);</span> 148 149<span class="special">}}</span> 150</pre> 151<h6> 152<a name="fiber.synchronization.channels.buffered_channel.h0"></a> 153 <span class="phrase"><a name="fiber.synchronization.channels.buffered_channel.constructor"></a></span><a class="link" href="buffered_channel.html#fiber.synchronization.channels.buffered_channel.constructor">Constructor</a> 154 </h6> 155<pre class="programlisting"><span class="keyword">explicit</span> <span class="identifier">buffered_channel</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">capacity</span><span class="special">);</span> 156</pre> 157<div class="variablelist"> 158<p class="title"><b></b></p> 159<dl class="variablelist"> 160<dt><span class="term">Preconditions:</span></dt> 161<dd><p> 162 <code class="computeroutput"><span class="number">2</span><span class="special"><=</span><span class="identifier">capacity</span> <span class="special">&&</span> 163 <span class="number">0</span><span class="special">==(</span><span class="identifier">capacity</span> <span class="special">&</span> 164 <span class="special">(</span><span class="identifier">capacity</span><span class="special">-</span><span class="number">1</span><span class="special">))</span></code> 165 </p></dd> 166<dt><span class="term">Effects:</span></dt> 167<dd><p> 168 The constructor constructs an object of class <code class="computeroutput"><span class="identifier">buffered_channel</span></code> 169 with an internal buffer of size <code class="computeroutput"><span class="identifier">capacity</span></code>. 170 </p></dd> 171<dt><span class="term">Throws:</span></dt> 172<dd><p> 173 <code class="computeroutput"><span class="identifier">fiber_error</span></code> 174 </p></dd> 175<dt><span class="term">Error Conditions:</span></dt> 176<dd><p> 177 <span class="bold"><strong>invalid_argument</strong></span>: if <code class="computeroutput"><span class="number">0</span><span class="special">==</span><span class="identifier">capacity</span> <span class="special">||</span> 178 <span class="number">0</span><span class="special">!=(</span><span class="identifier">capacity</span> <span class="special">&</span> 179 <span class="special">(</span><span class="identifier">capacity</span><span class="special">-</span><span class="number">1</span><span class="special">))</span></code>. 180 </p></dd> 181<dt><span class="term">Notes:</span></dt> 182<dd><p> 183 A <code class="computeroutput"><span class="identifier">push</span><span class="special">()</span></code>, 184 <code class="computeroutput"><span class="identifier">push_wait_for</span><span class="special">()</span></code> 185 or <code class="computeroutput"><span class="identifier">push_wait_until</span><span class="special">()</span></code> will not block until the number 186 of values in the channel becomes equal to <code class="computeroutput"><span class="identifier">capacity</span></code>. 187 The channel can hold only <code class="computeroutput"><span class="identifier">capacity</span> 188 <span class="special">-</span> <span class="number">1</span></code> 189 elements, otherwise it is considered to be full. 190 </p></dd> 191</dl> 192</div> 193<p> 194 </p> 195<h5> 196<a name="buffered_channel_close_bridgehead"></a> 197 <span class="phrase"><a name="buffered_channel_close"></a></span> 198 <a class="link" href="buffered_channel.html#buffered_channel_close">Member 199 function <code class="computeroutput">close</code>()</a> 200</h5> 201<p> 202 </p> 203<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">close</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span> 204</pre> 205<div class="variablelist"> 206<p class="title"><b></b></p> 207<dl class="variablelist"> 208<dt><span class="term">Effects:</span></dt> 209<dd><p> 210 Deactivates the channel. No values can be put after calling <code class="computeroutput"><span class="keyword">this</span><span class="special">-></span><span class="identifier">close</span><span class="special">()</span></code>. 211 Fibers blocked in <code class="computeroutput"><span class="keyword">this</span><span class="special">-></span><span class="identifier">pop</span><span class="special">()</span></code>, <code class="computeroutput"><span class="keyword">this</span><span class="special">-></span><span class="identifier">pop_wait_for</span><span class="special">()</span></code> or <code class="computeroutput"><span class="keyword">this</span><span class="special">-></span><span class="identifier">pop_wait_until</span><span class="special">()</span></code> will return <code class="computeroutput"><span class="identifier">closed</span></code>. 212 Fibers blocked in <code class="computeroutput"><span class="keyword">this</span><span class="special">-></span><span class="identifier">value_pop</span><span class="special">()</span></code> will receive an exception. 213 </p></dd> 214<dt><span class="term">Throws:</span></dt> 215<dd><p> 216 Nothing. 217 </p></dd> 218<dt><span class="term">Note:</span></dt> 219<dd><p> 220 <code class="computeroutput"><span class="identifier">close</span><span class="special">()</span></code> 221 is like closing a pipe. It informs waiting consumers that no more 222 values will arrive. 223 </p></dd> 224</dl> 225</div> 226<p> 227 </p> 228<h5> 229<a name="buffered_channel_push_bridgehead"></a> 230 <span class="phrase"><a name="buffered_channel_push"></a></span> 231 <a class="link" href="buffered_channel.html#buffered_channel_push">Member 232 function <code class="computeroutput">push</code>()</a> 233</h5> 234<p> 235 </p> 236<pre class="programlisting"><span class="identifier">channel_op_status</span> <span class="identifier">push</span><span class="special">(</span> <span class="identifier">value_type</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">va</span><span class="special">);</span> 237<span class="identifier">channel_op_status</span> <span class="identifier">push</span><span class="special">(</span> <span class="identifier">value_type</span> <span class="special">&&</span> <span class="identifier">va</span><span class="special">);</span> 238</pre> 239<div class="variablelist"> 240<p class="title"><b></b></p> 241<dl class="variablelist"> 242<dt><span class="term">Effects:</span></dt> 243<dd><p> 244 If channel is closed, returns <code class="computeroutput"><span class="identifier">closed</span></code>. 245 Otherwise enqueues the value in the channel, wakes up a fiber blocked 246 on <code class="computeroutput"><span class="keyword">this</span><span class="special">-></span><span class="identifier">pop</span><span class="special">()</span></code>, 247 <code class="computeroutput"><span class="keyword">this</span><span class="special">-></span><span class="identifier">value_pop</span><span class="special">()</span></code>, 248 <code class="computeroutput"><span class="keyword">this</span><span class="special">-></span><span class="identifier">pop_wait_for</span><span class="special">()</span></code> 249 or <code class="computeroutput"><span class="keyword">this</span><span class="special">-></span><span class="identifier">pop_wait_until</span><span class="special">()</span></code> 250 and returns <code class="computeroutput"><span class="identifier">success</span></code>. 251 If the channel is full, the fiber is blocked. 252 </p></dd> 253<dt><span class="term">Throws:</span></dt> 254<dd><p> 255 Exceptions thrown by copy- or move-operations. 256 </p></dd> 257</dl> 258</div> 259<p> 260 </p> 261<h5> 262<a name="buffered_channel_try_push_bridgehead"></a> 263 <span class="phrase"><a name="buffered_channel_try_push"></a></span> 264 <a class="link" href="buffered_channel.html#buffered_channel_try_push">Member 265 function <code class="computeroutput">try_push</code>()</a> 266</h5> 267<p> 268 </p> 269<pre class="programlisting"><span class="identifier">channel_op_status</span> <span class="identifier">try_push</span><span class="special">(</span> <span class="identifier">value_type</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">va</span><span class="special">);</span> 270<span class="identifier">channel_op_status</span> <span class="identifier">try_push</span><span class="special">(</span> <span class="identifier">value_type</span> <span class="special">&&</span> <span class="identifier">va</span><span class="special">);</span> 271</pre> 272<div class="variablelist"> 273<p class="title"><b></b></p> 274<dl class="variablelist"> 275<dt><span class="term">Effects:</span></dt> 276<dd><p> 277 If channel is closed, returns <code class="computeroutput"><span class="identifier">closed</span></code>. 278 Otherwise enqueues the value in the channel, wakes up a fiber blocked 279 on <code class="computeroutput"><span class="keyword">this</span><span class="special">-></span><span class="identifier">pop</span><span class="special">()</span></code>, 280 <code class="computeroutput"><span class="keyword">this</span><span class="special">-></span><span class="identifier">value_pop</span><span class="special">()</span></code>, 281 <code class="computeroutput"><span class="keyword">this</span><span class="special">-></span><span class="identifier">pop_wait_for</span><span class="special">()</span></code> 282 or <code class="computeroutput"><span class="keyword">this</span><span class="special">-></span><span class="identifier">pop_wait_until</span><span class="special">()</span></code> 283 and returns <code class="computeroutput"><span class="identifier">success</span></code>. 284 If the channel is full, it doesn't block and returns <code class="computeroutput"><span class="identifier">full</span></code>. 285 </p></dd> 286<dt><span class="term">Throws:</span></dt> 287<dd><p> 288 Exceptions thrown by copy- or move-operations. 289 </p></dd> 290</dl> 291</div> 292<p> 293 </p> 294<h5> 295<a name="buffered_channel_pop_bridgehead"></a> 296 <span class="phrase"><a name="buffered_channel_pop"></a></span> 297 <a class="link" href="buffered_channel.html#buffered_channel_pop">Member 298 function <code class="computeroutput">pop</code>()</a> 299</h5> 300<p> 301 </p> 302<pre class="programlisting"><span class="identifier">channel_op_status</span> <span class="identifier">pop</span><span class="special">(</span> <span class="identifier">value_type</span> <span class="special">&</span> <span class="identifier">va</span><span class="special">);</span> 303</pre> 304<div class="variablelist"> 305<p class="title"><b></b></p> 306<dl class="variablelist"> 307<dt><span class="term">Effects:</span></dt> 308<dd><p> 309 Dequeues a value from the channel. If the channel is empty, the fiber 310 gets suspended until at least one new item is <code class="computeroutput"><span class="identifier">push</span><span class="special">()</span></code>ed (return value <code class="computeroutput"><span class="identifier">success</span></code> 311 and <code class="computeroutput"><span class="identifier">va</span></code> contains dequeued 312 value) or the channel gets <code class="computeroutput"><span class="identifier">close</span><span class="special">()</span></code>d (return value <code class="computeroutput"><span class="identifier">closed</span></code>). 313 </p></dd> 314<dt><span class="term">Throws:</span></dt> 315<dd><p> 316 Exceptions thrown by copy- or move-operations. 317 </p></dd> 318</dl> 319</div> 320<p> 321 </p> 322<h5> 323<a name="buffered_channel_value_pop_bridgehead"></a> 324 <span class="phrase"><a name="buffered_channel_value_pop"></a></span> 325 <a class="link" href="buffered_channel.html#buffered_channel_value_pop">Member 326 function <code class="computeroutput">value_pop</code>()</a> 327</h5> 328<p> 329 </p> 330<pre class="programlisting"><span class="identifier">value_type</span> <span class="identifier">value_pop</span><span class="special">();</span> 331</pre> 332<div class="variablelist"> 333<p class="title"><b></b></p> 334<dl class="variablelist"> 335<dt><span class="term">Effects:</span></dt> 336<dd><p> 337 Dequeues a value from the channel. If the channel is empty, the fiber 338 gets suspended until at least one new item is <code class="computeroutput"><span class="identifier">push</span><span class="special">()</span></code>ed or the channel gets <code class="computeroutput"><span class="identifier">close</span><span class="special">()</span></code>d 339 (which throws an exception). 340 </p></dd> 341<dt><span class="term">Throws:</span></dt> 342<dd><p> 343 <code class="computeroutput"><span class="identifier">fiber_error</span></code> if <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code> 344 is closed or by copy- or move-operations. 345 </p></dd> 346<dt><span class="term">Error conditions:</span></dt> 347<dd><p> 348 <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">errc</span><span class="special">::</span><span class="identifier">operation_not_permitted</span></code> 349 </p></dd> 350</dl> 351</div> 352<p> 353 </p> 354<h5> 355<a name="buffered_channel_try_pop_bridgehead"></a> 356 <span class="phrase"><a name="buffered_channel_try_pop"></a></span> 357 <a class="link" href="buffered_channel.html#buffered_channel_try_pop">Member 358 function <code class="computeroutput">try_pop</code>()</a> 359</h5> 360<p> 361 </p> 362<pre class="programlisting"><span class="identifier">channel_op_status</span> <span class="identifier">try_pop</span><span class="special">(</span> <span class="identifier">value_type</span> <span class="special">&</span> <span class="identifier">va</span><span class="special">);</span> 363</pre> 364<div class="variablelist"> 365<p class="title"><b></b></p> 366<dl class="variablelist"> 367<dt><span class="term">Effects:</span></dt> 368<dd><p> 369 If channel is empty, returns <code class="computeroutput"><span class="identifier">empty</span></code>. 370 If channel is closed, returns <code class="computeroutput"><span class="identifier">closed</span></code>. 371 Otherwise it returns <code class="computeroutput"><span class="identifier">success</span></code> 372 and <code class="computeroutput"><span class="identifier">va</span></code> contains the 373 dequeued value. 374 </p></dd> 375<dt><span class="term">Throws:</span></dt> 376<dd><p> 377 Exceptions thrown by copy- or move-operations. 378 </p></dd> 379</dl> 380</div> 381<p> 382 </p> 383<h5> 384<a name="buffered_channel_pop_wait_for_bridgehead"></a> 385 <span class="phrase"><a name="buffered_channel_pop_wait_for"></a></span> 386 <a class="link" href="buffered_channel.html#buffered_channel_pop_wait_for">Member 387 function <code class="computeroutput">pop_wait_for</code>()</a> 388</h5> 389<p> 390 </p> 391<pre class="programlisting"><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> 392<span class="identifier">channel_op_status</span> <span class="identifier">pop_wait_for</span><span class="special">(</span> 393 <span class="identifier">value_type</span> <span class="special">&</span> <span class="identifier">va</span><span class="special">,</span> 394 <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">timeout_duration</span><span class="special">)</span> 395</pre> 396<div class="variablelist"> 397<p class="title"><b></b></p> 398<dl class="variablelist"> 399<dt><span class="term">Effects:</span></dt> 400<dd><p> 401 Accepts <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration</span></code> and internally computes 402 a timeout time as (system time + <code class="computeroutput"><span class="identifier">timeout_duration</span></code>). 403 If channel is not empty, immediately dequeues a value from the channel. 404 Otherwise the fiber gets suspended until at least one new item is 405 <code class="computeroutput"><span class="identifier">push</span><span class="special">()</span></code>ed 406 (return value <code class="computeroutput"><span class="identifier">success</span></code> 407 and <code class="computeroutput"><span class="identifier">va</span></code> contains dequeued 408 value), or the channel gets <code class="computeroutput"><span class="identifier">close</span><span class="special">()</span></code>d (return value <code class="computeroutput"><span class="identifier">closed</span></code>), 409 or the system time reaches the computed timeout time (return value 410 <code class="computeroutput"><span class="identifier">timeout</span></code>). 411 </p></dd> 412<dt><span class="term">Throws:</span></dt> 413<dd><p> 414 timeout-related exceptions or by copy- or move-operations. 415 </p></dd> 416</dl> 417</div> 418<p> 419 </p> 420<h5> 421<a name="buffered_channel_pop_wait_until_bridgehead"></a> 422 <span class="phrase"><a name="buffered_channel_pop_wait_until"></a></span> 423 <a class="link" href="buffered_channel.html#buffered_channel_pop_wait_until">Member 424 function <code class="computeroutput">pop_wait_until</code>()</a> 425</h5> 426<p> 427 </p> 428<pre class="programlisting"><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> 429<span class="identifier">channel_op_status</span> <span class="identifier">pop_wait_until</span><span class="special">(</span> 430 <span class="identifier">value_type</span> <span class="special">&</span> <span class="identifier">va</span><span class="special">,</span> 431 <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">timeout_time</span><span class="special">)</span> 432</pre> 433<div class="variablelist"> 434<p class="title"><b></b></p> 435<dl class="variablelist"> 436<dt><span class="term">Effects:</span></dt> 437<dd><p> 438 Accepts a <code class="computeroutput"><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> 439 <span class="identifier">Clock</span><span class="special">,</span> 440 <span class="identifier">Duration</span> <span class="special">></span></code>. 441 If channel is not empty, immediately dequeues a value from the channel. 442 Otherwise the fiber gets suspended until at least one new item is 443 <code class="computeroutput"><span class="identifier">push</span><span class="special">()</span></code>ed 444 (return value <code class="computeroutput"><span class="identifier">success</span></code> 445 and <code class="computeroutput"><span class="identifier">va</span></code> contains dequeued 446 value), or the channel gets <code class="computeroutput"><span class="identifier">close</span><span class="special">()</span></code>d (return value <code class="computeroutput"><span class="identifier">closed</span></code>), 447 or the system time reaches the passed <code class="computeroutput"><span class="identifier">time_point</span></code> 448 (return value <code class="computeroutput"><span class="identifier">timeout</span></code>). 449 </p></dd> 450<dt><span class="term">Throws:</span></dt> 451<dd><p> 452 timeout-related exceptions or by copy- or move-operations. 453 </p></dd> 454</dl> 455</div> 456<h6> 457<a name="fiber.synchronization.channels.buffered_channel.h1"></a> 458 <span class="phrase"><a name="fiber.synchronization.channels.buffered_channel.non_member_function__code__phrase_role__identifier__begin__phrase__phrase_role__special_____phrase___phrase_role__identifier__buffered_channel__phrase__phrase_role__special___lt___phrase___phrase_role__identifier__t__phrase___phrase_role__special___gt___phrase___phrase_role__special___amp____phrase___code_"></a></span><a class="link" href="buffered_channel.html#fiber.synchronization.channels.buffered_channel.non_member_function__code__phrase_role__identifier__begin__phrase__phrase_role__special_____phrase___phrase_role__identifier__buffered_channel__phrase__phrase_role__special___lt___phrase___phrase_role__identifier__t__phrase___phrase_role__special___gt___phrase___phrase_role__special___amp____phrase___code_">Non-member 459 function <code class="computeroutput"><span class="identifier">begin</span><span class="special">(</span> 460 <span class="identifier">buffered_channel</span><span class="special"><</span> 461 <span class="identifier">T</span> <span class="special">></span> 462 <span class="special">&)</span></code></a> 463 </h6> 464<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">></span> 465<span class="identifier">buffered_channel</span><span class="special"><</span> <span class="identifier">T</span> <span class="special">>::</span><span class="identifier">iterator</span> <span class="identifier">begin</span><span class="special">(</span> <span class="identifier">buffered_channel</span><span class="special"><</span> <span class="identifier">T</span> <span class="special">></span> <span class="special">&);</span> 466</pre> 467<div class="variablelist"> 468<p class="title"><b></b></p> 469<dl class="variablelist"> 470<dt><span class="term">Returns:</span></dt> 471<dd><p> 472 Returns a range-iterator (input-iterator). 473 </p></dd> 474</dl> 475</div> 476<h6> 477<a name="fiber.synchronization.channels.buffered_channel.h2"></a> 478 <span class="phrase"><a name="fiber.synchronization.channels.buffered_channel.non_member_function__code__phrase_role__identifier__end__phrase__phrase_role__special_____phrase___phrase_role__identifier__buffered_channel__phrase__phrase_role__special___lt___phrase___phrase_role__identifier__t__phrase___phrase_role__special___gt___phrase___phrase_role__special___amp____phrase___code_"></a></span><a class="link" href="buffered_channel.html#fiber.synchronization.channels.buffered_channel.non_member_function__code__phrase_role__identifier__end__phrase__phrase_role__special_____phrase___phrase_role__identifier__buffered_channel__phrase__phrase_role__special___lt___phrase___phrase_role__identifier__t__phrase___phrase_role__special___gt___phrase___phrase_role__special___amp____phrase___code_">Non-member 479 function <code class="computeroutput"><span class="identifier">end</span><span class="special">(</span> 480 <span class="identifier">buffered_channel</span><span class="special"><</span> 481 <span class="identifier">T</span> <span class="special">></span> 482 <span class="special">&)</span></code></a> 483 </h6> 484<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">></span> 485<span class="identifier">buffered_channel</span><span class="special"><</span> <span class="identifier">R</span> <span class="special">>::</span><span class="identifier">iterator</span> <span class="identifier">end</span><span class="special">(</span> <span class="identifier">buffered_channel</span><span class="special"><</span> <span class="identifier">T</span> <span class="special">></span> <span class="special">&);</span> 486</pre> 487<div class="variablelist"> 488<p class="title"><b></b></p> 489<dl class="variablelist"> 490<dt><span class="term">Returns:</span></dt> 491<dd><p> 492 Returns an end range-iterator (input-iterator). 493 </p></dd> 494</dl> 495</div> 496</div> 497<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 498<td align="left"></td> 499<td align="right"><div class="copyright-footer">Copyright © 2013 Oliver Kowalke<p> 500 Distributed under the Boost Software License, Version 1.0. (See accompanying 501 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>) 502 </p> 503</div></td> 504</tr></table> 505<hr> 506<div class="spirit-nav"> 507<a accesskey="p" href="../channels.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../channels.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="unbuffered_channel.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 508</div> 509</body> 510</html> 511