• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Unbuffered 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="buffered_channel.html" title="Buffered Channel">
10<link rel="next" href="../futures.html" title="Futures">
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="buffered_channel.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="../futures.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.unbuffered_channel"></a><a class="link" href="unbuffered_channel.html" title="Unbuffered Channel">Unbuffered
28        Channel</a>
29</h4></div></div></div>
30<p>
31          <span class="bold"><strong>Boost.Fiber</strong></span> provides template <code class="computeroutput"><span class="identifier">unbuffered_channel</span></code> suitable to synchonize
32          fibers (running on same or different threads) via synchronous message passing.
33          A fiber waiting to consume an value will block until the value is produced.
34          If a fiber attempts to send a value through an unbuffered channel and no
35          fiber is waiting to receive the value, the channel will block the sending
36          fiber.
37        </p>
38<p>
39          The unbuffered channel acts as an <code class="computeroutput"><span class="identifier">rendezvous</span>
40          <span class="identifier">point</span></code>.
41        </p>
42<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">unbuffered_channel</span><span class="special">&lt;</span> <span class="keyword">int</span> <span class="special">&gt;</span> <span class="identifier">channel_t</span><span class="special">;</span>
43
44<span class="keyword">void</span> <span class="identifier">send</span><span class="special">(</span> <span class="identifier">channel_t</span> <span class="special">&amp;</span> <span class="identifier">chan</span><span class="special">)</span> <span class="special">{</span>
45    <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">&lt;</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>
46        <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>
47    <span class="special">}</span>
48    <span class="identifier">chan</span><span class="special">.</span><span class="identifier">close</span><span class="special">();</span>
49<span class="special">}</span>
50
51<span class="keyword">void</span> <span class="identifier">recv</span><span class="special">(</span> <span class="identifier">channel_t</span> <span class="special">&amp;</span> <span class="identifier">chan</span><span class="special">)</span> <span class="special">{</span>
52    <span class="keyword">int</span> <span class="identifier">i</span><span class="special">;</span>
53    <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>
54        <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"received "</span> <span class="special">&lt;&lt;</span> <span class="identifier">i</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
55    <span class="special">}</span>
56<span class="special">}</span>
57
58<span class="identifier">channel_t</span> <span class="identifier">chan</span><span class="special">{</span> <span class="number">1</span> <span class="special">};</span>
59<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>
60<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>
61
62<span class="identifier">f1</span><span class="special">.</span><span class="identifier">join</span><span class="special">();</span>
63<span class="identifier">f2</span><span class="special">.</span><span class="identifier">join</span><span class="special">();</span>
64</pre>
65<p>
66          Range-for syntax is supported:
67        </p>
68<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">unbuffered_channel</span><span class="special">&lt;</span> <span class="keyword">int</span> <span class="special">&gt;</span> <span class="identifier">channel_t</span><span class="special">;</span>
69
70<span class="keyword">void</span> <span class="identifier">foo</span><span class="special">(</span> <span class="identifier">channel_t</span> <span class="special">&amp;</span> <span class="identifier">chan</span><span class="special">)</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">1</span><span class="special">);</span>
72    <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>
73    <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>
74    <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>
75    <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>
76    <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>
77    <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>
78    <span class="identifier">chan</span><span class="special">.</span><span class="identifier">close</span><span class="special">();</span>
79<span class="special">}</span>
80
81<span class="keyword">void</span> <span class="identifier">bar</span><span class="special">(</span> <span class="identifier">channel_t</span> <span class="special">&amp;</span> <span class="identifier">chan</span><span class="special">)</span> <span class="special">{</span>
82    <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>
83        <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">value</span> <span class="special">&lt;&lt;</span> <span class="string">" "</span><span class="special">;</span>
84    <span class="special">}</span>
85    <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
86<span class="special">}</span>
87</pre>
88<p>
89          </p>
90<h5>
91<a name="class_unbuffered_channel_bridgehead"></a>
92  <span class="phrase"><a name="class_unbuffered_channel"></a></span>
93  <a class="link" href="unbuffered_channel.html#class_unbuffered_channel">Template
94          <code class="computeroutput">unbuffered_channel&lt;&gt;</code></a>
95</h5>
96<p>
97        </p>
98<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">fiber</span><span class="special">/</span><span class="identifier">unbuffered_channel</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
99
100<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span>
101<span class="keyword">namespace</span> <span class="identifier">fibers</span> <span class="special">{</span>
102
103<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">&gt;</span>
104<span class="keyword">class</span> <span class="identifier">unbuffered_channel</span> <span class="special">{</span>
105<span class="keyword">public</span><span class="special">:</span>
106    <span class="keyword">typedef</span> <span class="identifier">T</span>   <span class="identifier">value_type</span><span class="special">;</span>
107
108    <span class="keyword">class</span> <span class="identifier">iterator</span><span class="special">;</span>
109
110    <span class="identifier">unbuffered_channel</span><span class="special">();</span>
111
112    <span class="identifier">unbuffered_channel</span><span class="special">(</span> <span class="identifier">unbuffered_channel</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">other</span><span class="special">)</span> <span class="special">=</span> <span class="keyword">delete</span><span class="special">;</span>
113    <span class="identifier">unbuffered_channel</span> <span class="special">&amp;</span> <span class="keyword">operator</span><span class="special">=(</span> <span class="identifier">unbuffered_channel</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">other</span><span class="special">)</span> <span class="special">=</span> <span class="keyword">delete</span><span class="special">;</span>
114
115    <span class="keyword">void</span> <span class="identifier">close</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span>
116
117    <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">&amp;</span> <span class="identifier">va</span><span class="special">);</span>
118    <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">&amp;&amp;</span> <span class="identifier">va</span><span class="special">);</span>
119    <span class="keyword">template</span><span class="special">&lt;</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">&gt;</span>
120    <span class="identifier">channel_op_status</span> <span class="identifier">push_wait_for</span><span class="special">(</span>
121        <span class="identifier">value_type</span> <span class="keyword">const</span><span class="special">&amp;</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">duration</span><span class="special">&lt;</span> <span class="identifier">Rep</span><span class="special">,</span> <span class="identifier">Period</span> <span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">timeout_duration</span><span class="special">);</span>
123    <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">&amp;&amp;</span> <span class="identifier">va</span><span class="special">,</span>
124        <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">&lt;</span> <span class="identifier">Rep</span><span class="special">,</span> <span class="identifier">Period</span> <span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">timeout_duration</span><span class="special">);</span>
125    <span class="keyword">template</span><span class="special">&lt;</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">&gt;</span>
126    <span class="identifier">channel_op_status</span> <span class="identifier">push_wait_until</span><span class="special">(</span>
127        <span class="identifier">value_type</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">va</span><span class="special">,</span>
128        <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">&lt;</span> <span class="identifier">Clock</span><span class="special">,</span> <span class="identifier">Duration</span> <span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">timeout_time</span><span class="special">);</span>
129    <span class="keyword">template</span><span class="special">&lt;</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">&gt;</span>
130    <span class="identifier">channel_op_status</span> <span class="identifier">push_wait_until</span><span class="special">(</span>
131        <span class="identifier">value_type</span> <span class="special">&amp;&amp;</span> <span class="identifier">va</span><span class="special">,</span>
132        <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">&lt;</span> <span class="identifier">Clock</span><span class="special">,</span> <span class="identifier">Duration</span> <span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">timeout_time</span><span class="special">);</span>
133
134    <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">&amp;</span> <span class="identifier">va</span><span class="special">);</span>
135    <span class="identifier">value_type</span> <span class="identifier">value_pop</span><span class="special">();</span>
136    <span class="keyword">template</span><span class="special">&lt;</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">&gt;</span>
137    <span class="identifier">channel_op_status</span> <span class="identifier">pop_wait_for</span><span class="special">(</span>
138        <span class="identifier">value_type</span> <span class="special">&amp;</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">duration</span><span class="special">&lt;</span> <span class="identifier">Rep</span><span class="special">,</span> <span class="identifier">Period</span> <span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">timeout_duration</span><span class="special">);</span>
140    <span class="keyword">template</span><span class="special">&lt;</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">&gt;</span>
141    <span class="identifier">channel_op_status</span> <span class="identifier">pop_wait_until</span><span class="special">(</span>
142        <span class="identifier">value_type</span> <span class="special">&amp;</span> <span class="identifier">va</span><span class="special">,</span>
143        <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">&lt;</span> <span class="identifier">Clock</span><span class="special">,</span> <span class="identifier">Duration</span> <span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">timeout_time</span><span class="special">);</span>
144<span class="special">};</span>
145
146<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">&gt;</span>
147<span class="identifier">unbuffered_channel</span><span class="special">&lt;</span> <span class="identifier">T</span> <span class="special">&gt;::</span><span class="identifier">iterator</span> <span class="identifier">begin</span><span class="special">(</span> <span class="identifier">unbuffered_channel</span><span class="special">&lt;</span> <span class="identifier">T</span> <span class="special">&gt;</span> <span class="special">&amp;</span> <span class="identifier">chan</span><span class="special">);</span>
148
149<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">&gt;</span>
150<span class="identifier">unbuffered_channel</span><span class="special">&lt;</span> <span class="identifier">T</span> <span class="special">&gt;::</span><span class="identifier">iterator</span> <span class="identifier">end</span><span class="special">(</span> <span class="identifier">unbuffered_channel</span><span class="special">&lt;</span> <span class="identifier">T</span> <span class="special">&gt;</span> <span class="special">&amp;</span> <span class="identifier">chan</span><span class="special">);</span>
151
152<span class="special">}}</span>
153</pre>
154<h6>
155<a name="fiber.synchronization.channels.unbuffered_channel.h0"></a>
156          <span class="phrase"><a name="fiber.synchronization.channels.unbuffered_channel.constructor"></a></span><a class="link" href="unbuffered_channel.html#fiber.synchronization.channels.unbuffered_channel.constructor">Constructor</a>
157        </h6>
158<pre class="programlisting"><span class="identifier">unbuffered_channel</span><span class="special">();</span>
159</pre>
160<div class="variablelist">
161<p class="title"><b></b></p>
162<dl class="variablelist">
163<dt><span class="term">Effects:</span></dt>
164<dd><p>
165                The constructor constructs an object of class <code class="computeroutput"><span class="identifier">unbuffered_channel</span></code>.
166              </p></dd>
167</dl>
168</div>
169<p>
170          </p>
171<h5>
172<a name="unbuffered_channel_close_bridgehead"></a>
173  <span class="phrase"><a name="unbuffered_channel_close"></a></span>
174  <a class="link" href="unbuffered_channel.html#unbuffered_channel_close">Member
175          function <code class="computeroutput">close</code>()</a>
176</h5>
177<p>
178        </p>
179<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>
180</pre>
181<div class="variablelist">
182<p class="title"><b></b></p>
183<dl class="variablelist">
184<dt><span class="term">Effects:</span></dt>
185<dd><p>
186                Deactivates the channel. No values can be put after calling <code class="computeroutput"><span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">close</span><span class="special">()</span></code>.
187                Fibers blocked in <code class="computeroutput"><span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">pop</span><span class="special">()</span></code>, <code class="computeroutput"><span class="keyword">this</span><span class="special">-&gt;</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">-&gt;</span><span class="identifier">pop_wait_until</span><span class="special">()</span></code> will return <code class="computeroutput"><span class="identifier">closed</span></code>.
188                Fibers blocked in <code class="computeroutput"><span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">value_pop</span><span class="special">()</span></code> will receive an exception.
189              </p></dd>
190<dt><span class="term">Throws:</span></dt>
191<dd><p>
192                Nothing.
193              </p></dd>
194<dt><span class="term">Note:</span></dt>
195<dd><p>
196                <code class="computeroutput"><span class="identifier">close</span><span class="special">()</span></code>
197                is like closing a pipe. It informs waiting consumers that no more
198                values will arrive.
199              </p></dd>
200</dl>
201</div>
202<p>
203          </p>
204<h5>
205<a name="unbuffered_channel_push_bridgehead"></a>
206  <span class="phrase"><a name="unbuffered_channel_push"></a></span>
207  <a class="link" href="unbuffered_channel.html#unbuffered_channel_push">Member
208          function <code class="computeroutput">push</code>()</a>
209</h5>
210<p>
211        </p>
212<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">&amp;</span> <span class="identifier">va</span><span class="special">);</span>
213<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">&amp;&amp;</span> <span class="identifier">va</span><span class="special">);</span>
214</pre>
215<div class="variablelist">
216<p class="title"><b></b></p>
217<dl class="variablelist">
218<dt><span class="term">Effects:</span></dt>
219<dd><p>
220                If channel is closed, returns <code class="computeroutput"><span class="identifier">closed</span></code>.
221                Otherwise enqueues the value in the channel, wakes up a fiber blocked
222                on <code class="computeroutput"><span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">pop</span><span class="special">()</span></code>,
223                <code class="computeroutput"><span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">value_pop</span><span class="special">()</span></code>,
224                <code class="computeroutput"><span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">pop_wait_for</span><span class="special">()</span></code>
225                or <code class="computeroutput"><span class="keyword">this</span><span class="special">-&gt;</span><span class="identifier">pop_wait_until</span><span class="special">()</span></code>
226                and returns <code class="computeroutput"><span class="identifier">success</span></code>.
227              </p></dd>
228<dt><span class="term">Throws:</span></dt>
229<dd><p>
230                Exceptions thrown by copy- or move-operations.
231              </p></dd>
232</dl>
233</div>
234<p>
235          </p>
236<h5>
237<a name="unbuffered_channel_pop_bridgehead"></a>
238  <span class="phrase"><a name="unbuffered_channel_pop"></a></span>
239  <a class="link" href="unbuffered_channel.html#unbuffered_channel_pop">Member
240          function <code class="computeroutput">pop</code>()</a>
241</h5>
242<p>
243        </p>
244<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">&amp;</span> <span class="identifier">va</span><span class="special">);</span>
245</pre>
246<div class="variablelist">
247<p class="title"><b></b></p>
248<dl class="variablelist">
249<dt><span class="term">Effects:</span></dt>
250<dd><p>
251                Dequeues a value from the channel. If the channel is empty, the fiber
252                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>
253                and <code class="computeroutput"><span class="identifier">va</span></code> contains dequeued
254                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>).
255              </p></dd>
256<dt><span class="term">Throws:</span></dt>
257<dd><p>
258                Exceptions thrown by copy- or move-operations.
259              </p></dd>
260</dl>
261</div>
262<p>
263          </p>
264<h5>
265<a name="unbuffered_channel_value_pop_bridgehead"></a>
266  <span class="phrase"><a name="unbuffered_channel_value_pop"></a></span>
267  <a class="link" href="unbuffered_channel.html#unbuffered_channel_value_pop">Member
268          function <code class="computeroutput">value_pop</code>()</a>
269</h5>
270<p>
271        </p>
272<pre class="programlisting"><span class="identifier">value_type</span> <span class="identifier">value_pop</span><span class="special">();</span>
273</pre>
274<div class="variablelist">
275<p class="title"><b></b></p>
276<dl class="variablelist">
277<dt><span class="term">Effects:</span></dt>
278<dd><p>
279                Dequeues a value from the channel. If the channel is empty, the fiber
280                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
281                (which throws an exception).
282              </p></dd>
283<dt><span class="term">Throws:</span></dt>
284<dd><p>
285                <code class="computeroutput"><span class="identifier">fiber_error</span></code> if <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
286                is closed or by copy- or move-operations.
287              </p></dd>
288<dt><span class="term">Error conditions:</span></dt>
289<dd><p>
290                <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>
291              </p></dd>
292</dl>
293</div>
294<p>
295          </p>
296<h5>
297<a name="unbuffered_channel_pop_wait_for_bridgehead"></a>
298  <span class="phrase"><a name="unbuffered_channel_pop_wait_for"></a></span>
299  <a class="link" href="unbuffered_channel.html#unbuffered_channel_pop_wait_for">Member
300          function <code class="computeroutput">pop_wait_for</code>()</a>
301</h5>
302<p>
303        </p>
304<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</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">&gt;</span>
305<span class="identifier">channel_op_status</span> <span class="identifier">pop_wait_for</span><span class="special">(</span>
306    <span class="identifier">value_type</span> <span class="special">&amp;</span> <span class="identifier">va</span><span class="special">,</span>
307    <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">&lt;</span> <span class="identifier">Rep</span><span class="special">,</span> <span class="identifier">Period</span> <span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">timeout_duration</span><span class="special">)</span>
308</pre>
309<div class="variablelist">
310<p class="title"><b></b></p>
311<dl class="variablelist">
312<dt><span class="term">Effects:</span></dt>
313<dd><p>
314                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
315                a timeout time as (system time + <code class="computeroutput"><span class="identifier">timeout_duration</span></code>).
316                If channel is not empty, immediately dequeues a value from the channel.
317                Otherwise the fiber gets suspended until at least one new item is
318                <code class="computeroutput"><span class="identifier">push</span><span class="special">()</span></code>ed
319                (return value <code class="computeroutput"><span class="identifier">success</span></code>
320                and <code class="computeroutput"><span class="identifier">va</span></code> contains dequeued
321                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>),
322                or the system time reaches the computed timeout time (return value
323                <code class="computeroutput"><span class="identifier">timeout</span></code>).
324              </p></dd>
325<dt><span class="term">Throws:</span></dt>
326<dd><p>
327                timeout-related exceptions or by copy- or move-operations.
328              </p></dd>
329</dl>
330</div>
331<p>
332          </p>
333<h5>
334<a name="unbuffered_channel_pop_wait_until_bridgehead"></a>
335  <span class="phrase"><a name="unbuffered_channel_pop_wait_until"></a></span>
336  <a class="link" href="unbuffered_channel.html#unbuffered_channel_pop_wait_until">Member
337          function <code class="computeroutput">pop_wait_until</code>()</a>
338</h5>
339<p>
340        </p>
341<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</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">&gt;</span>
342<span class="identifier">channel_op_status</span> <span class="identifier">pop_wait_until</span><span class="special">(</span>
343    <span class="identifier">value_type</span> <span class="special">&amp;</span> <span class="identifier">va</span><span class="special">,</span>
344    <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">&lt;</span> <span class="identifier">Clock</span><span class="special">,</span> <span class="identifier">Duration</span> <span class="special">&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">timeout_time</span><span class="special">)</span>
345</pre>
346<div class="variablelist">
347<p class="title"><b></b></p>
348<dl class="variablelist">
349<dt><span class="term">Effects:</span></dt>
350<dd><p>
351                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">&lt;</span>
352                <span class="identifier">Clock</span><span class="special">,</span>
353                <span class="identifier">Duration</span> <span class="special">&gt;</span></code>.
354                If channel is not empty, immediately dequeues a value from the channel.
355                Otherwise the fiber gets suspended until at least one new item is
356                <code class="computeroutput"><span class="identifier">push</span><span class="special">()</span></code>ed
357                (return value <code class="computeroutput"><span class="identifier">success</span></code>
358                and <code class="computeroutput"><span class="identifier">va</span></code> contains dequeued
359                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>),
360                or the system time reaches the passed <code class="computeroutput"><span class="identifier">time_point</span></code>
361                (return value <code class="computeroutput"><span class="identifier">timeout</span></code>).
362              </p></dd>
363<dt><span class="term">Throws:</span></dt>
364<dd><p>
365                timeout-related exceptions or by copy- or move-operations.
366              </p></dd>
367</dl>
368</div>
369<h6>
370<a name="fiber.synchronization.channels.unbuffered_channel.h1"></a>
371          <span class="phrase"><a name="fiber.synchronization.channels.unbuffered_channel.non_member_function__code__phrase_role__identifier__begin__phrase__phrase_role__special_____phrase___phrase_role__identifier__unbuffered_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="unbuffered_channel.html#fiber.synchronization.channels.unbuffered_channel.non_member_function__code__phrase_role__identifier__begin__phrase__phrase_role__special_____phrase___phrase_role__identifier__unbuffered_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
372          function <code class="computeroutput"><span class="identifier">begin</span><span class="special">(</span>
373          <span class="identifier">unbuffered_channel</span><span class="special">&lt;</span>
374          <span class="identifier">T</span> <span class="special">&gt;</span>
375          <span class="special">&amp;)</span></code></a>
376        </h6>
377<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">&gt;</span>
378<span class="identifier">unbuffered_channel</span><span class="special">&lt;</span> <span class="identifier">T</span> <span class="special">&gt;::</span><span class="identifier">iterator</span> <span class="identifier">begin</span><span class="special">(</span> <span class="identifier">unbuffered_channel</span><span class="special">&lt;</span> <span class="identifier">T</span> <span class="special">&gt;</span> <span class="special">&amp;);</span>
379</pre>
380<div class="variablelist">
381<p class="title"><b></b></p>
382<dl class="variablelist">
383<dt><span class="term">Returns:</span></dt>
384<dd><p>
385                Returns a range-iterator (input-iterator).
386              </p></dd>
387</dl>
388</div>
389<h6>
390<a name="fiber.synchronization.channels.unbuffered_channel.h2"></a>
391          <span class="phrase"><a name="fiber.synchronization.channels.unbuffered_channel.non_member_function__code__phrase_role__identifier__end__phrase__phrase_role__special_____phrase___phrase_role__identifier__unbuffered_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="unbuffered_channel.html#fiber.synchronization.channels.unbuffered_channel.non_member_function__code__phrase_role__identifier__end__phrase__phrase_role__special_____phrase___phrase_role__identifier__unbuffered_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
392          function <code class="computeroutput"><span class="identifier">end</span><span class="special">(</span>
393          <span class="identifier">unbuffered_channel</span><span class="special">&lt;</span>
394          <span class="identifier">T</span> <span class="special">&gt;</span>
395          <span class="special">&amp;)</span></code></a>
396        </h6>
397<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">T</span> <span class="special">&gt;</span>
398<span class="identifier">unbuffered_channel</span><span class="special">&lt;</span> <span class="identifier">R</span> <span class="special">&gt;::</span><span class="identifier">iterator</span> <span class="identifier">end</span><span class="special">(</span> <span class="identifier">unbuffered_channel</span><span class="special">&lt;</span> <span class="identifier">T</span> <span class="special">&gt;</span> <span class="special">&amp;);</span>
399</pre>
400<div class="variablelist">
401<p class="title"><b></b></p>
402<dl class="variablelist">
403<dt><span class="term">Returns:</span></dt>
404<dd><p>
405                Returns an end range-iterator (input-iterator).
406              </p></dd>
407</dl>
408</div>
409</div>
410<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
411<td align="left"></td>
412<td align="right"><div class="copyright-footer">Copyright © 2013 Oliver Kowalke<p>
413        Distributed under the Boost Software License, Version 1.0. (See accompanying
414        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>)
415      </p>
416</div></td>
417</tr></table>
418<hr>
419<div class="spirit-nav">
420<a accesskey="p" href="buffered_channel.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="../futures.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
421</div>
422</body>
423</html>
424