Fix comments

This commit is contained in:
Erazem Kokot 2023-10-01 22:56:19 +02:00
parent e988ebce0c
commit e6745799a0
No known key found for this signature in database
GPG Key ID: C70635965D7AC47F
3 changed files with 11 additions and 19 deletions

View File

@ -31,9 +31,7 @@ func main() {
go func() {
for c := 0; c < 1000; c++ {
// To atomically increment the counter we use `Add`,
// giving it the memory address of our `ops` counter
// with the `&` syntax.
// To atomically increment the counter we use `Add`.
ops.Add(1)
}
@ -44,10 +42,8 @@ func main() {
// Wait until all the goroutines are done.
wg.Wait()
// It's safe to access `ops` now because we know
// no other goroutine is writing to it. Reading
// atomics safely while they are being updated is
// also possible, using functions like
// `atomic.LoadUint64`.
// Reading atomics safely while they are being updated is
// possible using functions like `Load`, although here it's
// safe anyway, because no goroutines are writing to 'ops'.
fmt.Println("ops:", ops.Load())
}

View File

@ -1,2 +1,2 @@
8c87658e3694b98a456c73438c453286fe018c28
5vAUgPMebQw
806f385f4485c3e9d10fe319744dd58ab77adaaf
LfAMxMppwL-

14
public/atomic-counters generated
View File

@ -46,7 +46,7 @@ counters</em> accessed by multiple goroutines.</p>
</td>
<td class="code leading">
<a href="https://go.dev/play/p/5vAUgPMebQw"><img title="Run code" src="play.png" class="run" /></a><img title="Copy code" src="clipboard.png" class="copy" />
<a href="https://go.dev/play/p/LfAMxMppwL-"><img title="Run code" src="play.png" class="run" /></a><img title="Copy code" src="clipboard.png" class="copy" />
<pre class="chroma"><code><span class="line"><span class="cl"><span class="kn">package</span> <span class="nx">main</span></span></span></code></pre>
</td>
</tr>
@ -125,9 +125,7 @@ counter exactly 1000 times.</p>
<tr>
<td class="docs">
<p>To atomically increment the counter we use <code>Add</code>,
giving it the memory address of our <code>ops</code> counter
with the <code>&amp;</code> syntax.</p>
<p>To atomically increment the counter we use <code>Add</code>.</p>
</td>
<td class="code leading">
@ -162,11 +160,9 @@ with the <code>&amp;</code> syntax.</p>
<tr>
<td class="docs">
<p>It&rsquo;s safe to access <code>ops</code> now because we know
no other goroutine is writing to it. Reading
atomics safely while they are being updated is
also possible, using functions like
<code>atomic.LoadUint64</code>.</p>
<p>Reading atomics safely while they are being updated is
possible using functions like <code>Load</code>, although here it&rsquo;s
safe anyway, because no goroutines are writing to &lsquo;ops&rsquo;.</p>
</td>
<td class="code">