From e6745799a03c8be65fd7648886023531b319d7b1 Mon Sep 17 00:00:00 2001 From: Erazem Kokot Date: Sun, 1 Oct 2023 22:56:19 +0200 Subject: [PATCH] Fix comments --- examples/atomic-counters/atomic-counters.go | 12 ++++-------- examples/atomic-counters/atomic-counters.hash | 4 ++-- public/atomic-counters | 14 +++++--------- 3 files changed, 11 insertions(+), 19 deletions(-) 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
@@ -125,9 +125,7 @@ counter exactly 1000 times.

-

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.

@@ -162,11 +160,9 @@ with the & 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’.