Skip to content

Commit de7a917

Browse files
authored
Merge pull request #196 from rokf/typo-fix
Tutorial typo fix
2 parents d958f29 + c9288eb commit de7a917

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

website/src/tutorial-basics.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Throughout the tutorial, you will learn how to use coroutines, channels, and soc
2222
## Step 1: Setting up the stage
2323

2424
Start by including the libdill header file. Later we'll need some functionality from the standard library, so include those headers as well:
25-
25+
2626
```c
2727
#include <libdill.h>
2828
#include <assert.h>
@@ -171,7 +171,7 @@ At this point, the client cannot crash the server, but it can block it. Do the f
171171
3. At yet another terminal, open a new telnet session.
172172
4. Observe that the second session hangs without even asking you for your name.
173173

174-
The reason for this behavior is that the program doesn't even start accepting new connections until the entire dialog with the client has finished. What we want instead is to run any number of dialogues with clients in parallel. And that is where coroutines kick in.
174+
The reason for this behavior is that the program doesn't even start accepting new connections until the entire dialogue with the client has finished. What we want instead is to run any number of dialogues with clients in parallel. And that is where coroutines kick in.
175175

176176
Coroutines are defined using the `coroutine` keyword and launched with the `go()` construct.
177177

@@ -197,13 +197,13 @@ int main(int argc, char *argv[]) {
197197
assert(s >= 0);
198198
s = suffix_attach(s, "\r\n", 2);
199199
assert(s >= 0);
200-
int cr = go(dialog(s));
200+
int cr = go(dialogue(s));
201201
assert(cr >= 0);
202202
}
203203
}
204204
```
205205
206-
Let's compile it and try the initial experiment once again. As can be seen, one client now cannot block another one. Excellent. Let's move on.
206+
Let's compile it and try the initial experiment once again. As can be seen, one client now cannot block another one. Excellent. Let's move on.
207207
208208
## Step 4: Shutdown
209209
@@ -244,7 +244,7 @@ int main(int argc, char *argv[]) {
244244
rc = hclose(ls);
245245
assert(rc == 0);
246246
247-
return 0;
247+
return 0;
248248
}
249249
```
250250

@@ -258,7 +258,7 @@ Now try to compile this step and run it under valgrind. (Don't forget to compile
258258
==179895== HEAP SUMMARY:
259259
==179895== in use at exit: 0 bytes in 0 blocks
260260
==179895== total heap usage: 11 allocs, 11 frees, 1,329,272 bytes allocated
261-
==179895==
261+
==179895==
262262
==179895== All heap blocks were freed -- no leaks are possible
263263
```
264264

@@ -270,7 +270,7 @@ File descriptors can be a scarce resource. If a client connects to the greetserv
270270

271271
To deal with the problem, we are going to timeout the whole client/server dialogue. If it takes more than *10* seconds, the server will kill the connection at once.
272272

273-
One thing to note is that libdill uses deadlines rather than the more conventional timeouts. In other words, you specify the time instant by which you want the operation to finish rather than the maximum time it should take to run it. To construct deadlines easily, libdill provides the `now()` function. The deadline is expressed in milliseconds, which means you can create a deadline one minure in the future as follows:
273+
One thing to note is that libdill uses deadlines rather than the more conventional timeouts. In other words, you specify the time instant by which you want the operation to finish rather than the maximum time it should take to run it. To construct deadlines easily, libdill provides the `now()` function. The deadline is expressed in milliseconds, which means you can create a deadline one minute in the future as follows:
274274

275275
```c
276276
int64_t deadline = now() + 60000;
@@ -296,7 +296,7 @@ This can be achieved by calling `bundle_wait()` on the `dialogue()` coroutine bu
296296
```c
297297
rc = bundle_wait(b, now() + 10000);
298298
assert(rc == 0 || (rc < 0 && errno == ETIMEDOUT));
299-
```
299+
```
300300
301301
## Step 6: Communication among coroutines
302302
@@ -356,7 +356,7 @@ coroutine void statistics(int ch) {
356356
int active = 0;
357357
int succeeded = 0;
358358
int failed = 0;
359-
359+
360360
while(1) {
361361
int op;
362362
int rc = chrecv(ch, &op, sizeof(op), -1);

website/tutorial-basics.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ <h2 id="step-3-making-it-parallel">Step 3: Making it parallel</h2>
113113
<li>At yet another terminal, open a new telnet session.</li>
114114
<li>Observe that the second session hangs without even asking you for your name.</li>
115115
</ol>
116-
<p>The reason for this behavior is that the program doesn't even start accepting new connections until the entire dialog with the client has finished. What we want instead is to run any number of dialogues with clients in parallel. And that is where coroutines kick in.</p>
116+
<p>The reason for this behavior is that the program doesn't even start accepting new connections until the entire dialogue with the client has finished. What we want instead is to run any number of dialogues with clients in parallel. And that is where coroutines kick in.</p>
117117
<p>Coroutines are defined using the <code>coroutine</code> keyword and launched with the <code>go()</code> construct.</p>
118118
<p>In our case, we can move the code performing the dialogue with the client into a separate function and launch it as a coroutine:</p>
119119
<div class="sourceCode"><pre class="sourceCode c"><code class="sourceCode c">coroutine <span class="dt">void</span> dialogue(<span class="dt">int</span> s) {
@@ -135,7 +135,7 @@ <h2 id="step-3-making-it-parallel">Step 3: Making it parallel</h2>
135135
assert(s &gt;= <span class="dv">0</span>);
136136
s = suffix_attach(s, <span class="st">&quot;</span><span class="sc">\r\n</span><span class="st">&quot;</span>, <span class="dv">2</span>);
137137
assert(s &gt;= <span class="dv">0</span>);
138-
<span class="dt">int</span> cr = go(dialog(s));
138+
<span class="dt">int</span> cr = go(dialogue(s));
139139
assert(cr &gt;= <span class="dv">0</span>);
140140
}
141141
}</code></pre></div>
@@ -170,21 +170,21 @@ <h2 id="step-4-shutdown">Step 4: Shutdown</h2>
170170
rc = hclose(ls);
171171
assert(rc == <span class="dv">0</span>);
172172

173-
<span class="cf">return</span> <span class="dv">0</span>;
173+
<span class="cf">return</span> <span class="dv">0</span>;
174174
}</code></pre></div>
175175
<p>One thing to remember about canceling coroutines is that once a coroutine is canceled all the blocking operations within the coroutine, such as reading from a socket or sleeping, will start returning <code>ECANCELED</code> error. The coroutine should then deallocate all its resources and exit.</p>
176176
<p>Looking at our <code>dialogue</code> coroutine it turns out that it already does that. It responds to any error, including <code>ECANCELED</code> by closing the socket handle and exiting.</p>
177177
<p>Now try to compile this step and run it under valgrind. (Don't forget to compile libdill itself with <code>--enable-valgrind</code> and <code>--disable-shared</code> options!) Here's what you'll get:</p>
178178
<pre><code>==179895== HEAP SUMMARY:
179179
==179895== in use at exit: 0 bytes in 0 blocks
180180
==179895== total heap usage: 11 allocs, 11 frees, 1,329,272 bytes allocated
181-
==179895==
181+
==179895==
182182
==179895== All heap blocks were freed -- no leaks are possible</code></pre>
183183
<p>To get some background on how object lifetimes are supposed to be managed in libdill read the article about <a href="structured-concurrency.html">structured concurrency</a>.</p>
184184
<h2 id="step-5-deadlines">Step 5: Deadlines</h2>
185185
<p>File descriptors can be a scarce resource. If a client connects to the greetserver and lets the dialogue hang without entering a name, one file descriptor on the server side is, for all intents and purposes, wasted.</p>
186186
<p>To deal with the problem, we are going to timeout the whole client/server dialogue. If it takes more than <em>10</em> seconds, the server will kill the connection at once.</p>
187-
<p>One thing to note is that libdill uses deadlines rather than the more conventional timeouts. In other words, you specify the time instant by which you want the operation to finish rather than the maximum time it should take to run it. To construct deadlines easily, libdill provides the <code>now()</code> function. The deadline is expressed in milliseconds, which means you can create a deadline one minure in the future as follows:</p>
187+
<p>One thing to note is that libdill uses deadlines rather than the more conventional timeouts. In other words, you specify the time instant by which you want the operation to finish rather than the maximum time it should take to run it. To construct deadlines easily, libdill provides the <code>now()</code> function. The deadline is expressed in milliseconds, which means you can create a deadline one minute in the future as follows:</p>
188188
<div class="sourceCode"><pre class="sourceCode c"><code class="sourceCode c"><span class="dt">int64_t</span> deadline = now() + <span class="dv">60000</span>;</code></pre></div>
189189
<p>Furthermore, you have to modify all potentially blocking function calls in the program to take the deadline parameter. In our case:</p>
190190
<div class="sourceCode"><pre class="sourceCode c"><code class="sourceCode c"><span class="dt">int64_t</span> deadline = now() + <span class="dv">60000</span>;
@@ -237,7 +237,7 @@ <h2 id="step-6-communication-among-coroutines">Step 6: Communication among corou
237237
<span class="dt">int</span> active = <span class="dv">0</span>;
238238
<span class="dt">int</span> succeeded = <span class="dv">0</span>;
239239
<span class="dt">int</span> failed = <span class="dv">0</span>;
240-
240+
241241
<span class="cf">while</span>(<span class="dv">1</span>) {
242242
<span class="dt">int</span> op;
243243
<span class="dt">int</span> rc = chrecv(ch, &amp;op, <span class="kw">sizeof</span>(op), <span class="dv">-1</span>);

0 commit comments

Comments
 (0)