diff --git a/examples/atomic-counters/atomic-counters.go b/examples/atomic-counters/atomic-counters.go index dd2e293..5f8a2d7 100644 --- a/examples/atomic-counters/atomic-counters.go +++ b/examples/atomic-counters/atomic-counters.go @@ -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()) } diff --git a/examples/atomic-counters/atomic-counters.hash b/examples/atomic-counters/atomic-counters.hash index 17ff05c..2e18a61 100644 --- a/examples/atomic-counters/atomic-counters.hash +++ b/examples/atomic-counters/atomic-counters.hash @@ -1,2 +1,2 @@ -8c87658e3694b98a456c73438c453286fe018c28 -5vAUgPMebQw +806f385f4485c3e9d10fe319744dd58ab77adaaf +LfAMxMppwL- diff --git a/public/atomic-counters b/public/atomic-counters index 1e62f72..0bd4299 100644 --- a/public/atomic-counters +++ b/public/atomic-counters @@ -46,7 +46,7 @@ counters accessed by multiple goroutines.
package main
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
.
&
syntax.
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’.