Skip to content

Commit ea59398

Browse files
authored
Merge pull request #62 from pedropark99/revision-14
Add a revision for Chapter 14
2 parents a3ed4ce + 2d618b3 commit ea59398

File tree

10 files changed

+96
-101
lines changed

10 files changed

+96
-101
lines changed

Chapters/01-base64.qmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ is the `Base64` struct itself. Therefore, this argument clearly signals
552552
that this function is a method from the `Base64` struct.
553553

554554
Because the `encode()` function itself is fairly long,
555-
I intentionally ommitted the `Base64` struct definition in this source code,
555+
I intentionally omitted the `Base64` struct definition in this source code,
556556
just for brevity reasons. So, just remember that this function is a public function (or a public method) from the
557557
`Base64` struct.
558558

Chapters/14-threads.qmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ In the example below, we are using our previous `print_id()` function once again
518518
But you may notice that the `print_id()` function is a little different this time,
519519
because now we are using `catch` instead of `try` in the `print()` call.
520520
Currently, the `Pool` struct only supports functions that don't return errors
521-
as tasks. Thus, when assigining tasks to threads in a thread pool, is essential to use functions
521+
as tasks. Thus, when assigning tasks to threads in a thread pool, is essential to use functions
522522
that don't return errors. That is why we are using `catch` here, so that the
523523
`print_id()` function don't return an error.
524524

Chapters/14-zig-c-interop.qmd

+46-50
Large diffs are not rendered by default.

_freeze/Chapters/01-base64/execute-results/html.json

+2-2
Large diffs are not rendered by default.

_freeze/Chapters/14-threads/execute-results/html.json

+2-2
Large diffs are not rendered by default.

_freeze/Chapters/14-zig-c-interop/execute-results/html.json

+2-2
Large diffs are not rendered by default.

docs/Chapters/01-base64.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ <h3 data-number="4.4.4" class="anchored" data-anchor-id="allocating-space-for-th
688688
<h3 data-number="4.4.5" class="anchored" data-anchor-id="writing-the-encode-function"><span class="header-section-number">4.4.5</span> Writing the <code>encode()</code> function</h3>
689689
<p>Now that we have a basic understanding on how the bitwise operators work, and how exactly they help us to achieve the result we want to achieve. We can now encapsulate all the logic that we have described at <a href="#fig-base64-algo1" class="quarto-xref">Figure&nbsp;<span>4.1</span></a> and <a href="#tbl-transf-6bit" class="quarto-xref">Table&nbsp;<span>4.1</span></a> into a nice function that we can add to our <code>Base64</code> struct definition, that we started at <a href="#sec-base64-table" class="quarto-xref"><span>Section 4.1.2</span></a>.</p>
690690
<p>You can find the <code>encode()</code> function below. Notice that the first argument of this function, is the <code>Base64</code> struct itself. Therefore, this argument clearly signals that this function is a method from the <code>Base64</code> struct.</p>
691-
<p>Because the <code>encode()</code> function itself is fairly long, I intentionally ommitted the <code>Base64</code> struct definition in this source code, just for brevity reasons. So, just remember that this function is a public function (or a public method) from the <code>Base64</code> struct.</p>
691+
<p>Because the <code>encode()</code> function itself is fairly long, I intentionally omitted the <code>Base64</code> struct definition in this source code, just for brevity reasons. So, just remember that this function is a public function (or a public method) from the <code>Base64</code> struct.</p>
692692
<p>Furthermore, this <code>encode()</code> function have two other arguments:</p>
693693
<ol type="1">
694694
<li><code>input</code> is the input sequence of characters that you want to encode in base64;</li>

docs/Chapters/14-threads.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ <h2 data-number="16.5" class="anchored" data-anchor-id="thread-pools"><span clas
575575
</div>
576576
<p>Now that we know how to create <code>Pool</code> objects, we have to understand how to assign tasks to be executed by the threads in this pool object. To assign a task to be performed by a thread, we need to call the <code>spawn()</code> method from the thread pool object.</p>
577577
<p>This <code>spawn()</code> method works identical to the <code>spawn()</code> method from the <code>Thread</code> object. The method have almost the same arguments as the previous one, more precisely, we don’t have to provide a <code>SpawnConfig</code> object in this case. But instead of creating a new thread, this <code>spawn()</code> method from the thread pool object just register a new task in the internal “queue of tasks” to be performed, and any available thread in the pool will get this task, and it will simply perform the task.</p>
578-
<p>In the example below, we are using our previous <code>print_id()</code> function once again. But you may notice that the <code>print_id()</code> function is a little different this time, because now we are using <code>catch</code> instead of <code>try</code> in the <code>print()</code> call. Currently, the <code>Pool</code> struct only supports functions that don’t return errors as tasks. Thus, when assigining tasks to threads in a thread pool, is essential to use functions that don’t return errors. That is why we are using <code>catch</code> here, so that the <code>print_id()</code> function don’t return an error.</p>
578+
<p>In the example below, we are using our previous <code>print_id()</code> function once again. But you may notice that the <code>print_id()</code> function is a little different this time, because now we are using <code>catch</code> instead of <code>try</code> in the <code>print()</code> call. Currently, the <code>Pool</code> struct only supports functions that don’t return errors as tasks. Thus, when assigning tasks to threads in a thread pool, is essential to use functions that don’t return errors. That is why we are using <code>catch</code> here, so that the <code>print_id()</code> function don’t return an error.</p>
579579
<div class="cell">
580580
<div class="sourceCode cell-code" id="cb11"><pre class="sourceCode zig code-with-copy"><code class="sourceCode zig"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="kw">fn</span> print_id(id: *<span class="kw">const</span> <span class="dt">u8</span>) <span class="dt">void</span> <span class="op">{</span></span>
581581
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a> _ = stdout.print(<span class="st">"Thread ID: {d}</span><span class="sc">\n</span><span class="st">"</span>, .<span class="op">{</span>id.*<span class="op">}</span>)</span>

0 commit comments

Comments
 (0)