Fix comments
This commit is contained in:
parent
e988ebce0c
commit
e6745799a0
@ -31,9 +31,7 @@ func main() {
|
|||||||
go func() {
|
go func() {
|
||||||
for c := 0; c < 1000; c++ {
|
for c := 0; c < 1000; c++ {
|
||||||
|
|
||||||
// To atomically increment the counter we use `Add`,
|
// To atomically increment the counter we use `Add`.
|
||||||
// giving it the memory address of our `ops` counter
|
|
||||||
// with the `&` syntax.
|
|
||||||
ops.Add(1)
|
ops.Add(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,10 +42,8 @@ func main() {
|
|||||||
// Wait until all the goroutines are done.
|
// Wait until all the goroutines are done.
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
// It's safe to access `ops` now because we know
|
// Reading atomics safely while they are being updated is
|
||||||
// no other goroutine is writing to it. Reading
|
// possible using functions like `Load`, although here it's
|
||||||
// atomics safely while they are being updated is
|
// safe anyway, because no goroutines are writing to 'ops'.
|
||||||
// also possible, using functions like
|
|
||||||
// `atomic.LoadUint64`.
|
|
||||||
fmt.Println("ops:", ops.Load())
|
fmt.Println("ops:", ops.Load())
|
||||||
}
|
}
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
8c87658e3694b98a456c73438c453286fe018c28
|
806f385f4485c3e9d10fe319744dd58ab77adaaf
|
||||||
5vAUgPMebQw
|
LfAMxMppwL-
|
||||||
|
14
public/atomic-counters
generated
14
public/atomic-counters
generated
@ -46,7 +46,7 @@ counters</em> accessed by multiple goroutines.</p>
|
|||||||
|
|
||||||
</td>
|
</td>
|
||||||
<td class="code leading">
|
<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>
|
<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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -125,9 +125,7 @@ counter exactly 1000 times.</p>
|
|||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td class="docs">
|
<td class="docs">
|
||||||
<p>To atomically increment the counter we use <code>Add</code>,
|
<p>To atomically increment the counter we use <code>Add</code>.</p>
|
||||||
giving it the memory address of our <code>ops</code> counter
|
|
||||||
with the <code>&</code> syntax.</p>
|
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
<td class="code leading">
|
<td class="code leading">
|
||||||
@ -162,11 +160,9 @@ with the <code>&</code> syntax.</p>
|
|||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td class="docs">
|
<td class="docs">
|
||||||
<p>It’s safe to access <code>ops</code> now because we know
|
<p>Reading atomics safely while they are being updated is
|
||||||
no other goroutine is writing to it. Reading
|
possible using functions like <code>Load</code>, although here it’s
|
||||||
atomics safely while they are being updated is
|
safe anyway, because no goroutines are writing to ‘ops’.</p>
|
||||||
also possible, using functions like
|
|
||||||
<code>atomic.LoadUint64</code>.</p>
|
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
<td class="code">
|
<td class="code">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user