Skip to content

Commit

Permalink
Merge pull request #62 from pedropark99/revision-14
Browse files Browse the repository at this point in the history
Add a revision for Chapter 14
  • Loading branch information
pedropark99 authored Oct 8, 2024
2 parents a3ed4ce + 2d618b3 commit ea59398
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 101 deletions.
2 changes: 1 addition & 1 deletion Chapters/01-base64.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ is the `Base64` struct itself. Therefore, this argument clearly signals
that this function is a method from the `Base64` struct.

Because the `encode()` function itself is fairly long,
I intentionally ommitted the `Base64` struct definition in this source code,
I intentionally omitted the `Base64` 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
`Base64` struct.

Expand Down
2 changes: 1 addition & 1 deletion Chapters/14-threads.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ In the example below, we are using our previous `print_id()` function once again
But you may notice that the `print_id()` function is a little different this time,
because now we are using `catch` instead of `try` in the `print()` call.
Currently, the `Pool` 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
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 `catch` here, so that the
`print_id()` function don't return an error.

Expand Down
96 changes: 46 additions & 50 deletions Chapters/14-zig-c-interop.qmd

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions _freeze/Chapters/01-base64/execute-results/html.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions _freeze/Chapters/14-threads/execute-results/html.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions _freeze/Chapters/14-zig-c-interop/execute-results/html.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Chapters/01-base64.html
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ <h3 data-number="4.4.4" class="anchored" data-anchor-id="allocating-space-for-th
<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>
<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>
<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>
<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>
<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>
<p>Furthermore, this <code>encode()</code> function have two other arguments:</p>
<ol type="1">
<li><code>input</code> is the input sequence of characters that you want to encode in base64;</li>
Expand Down
2 changes: 1 addition & 1 deletion docs/Chapters/14-threads.html
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ <h2 data-number="16.5" class="anchored" data-anchor-id="thread-pools"><span clas
</div>
<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>
<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>
<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>
<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>
<div class="cell">
<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>
<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>
Expand Down
Loading

0 comments on commit ea59398

Please sign in to comment.