From edab9620548a16993a2341d9d1d71ac8dadd4299 Mon Sep 17 00:00:00 2001
From: Eli Bendersky
Date: Mon, 2 Oct 2023 05:48:21 -0700
Subject: [PATCH] Small comment updates to atomic-counters
---
examples/atomic-counters/atomic-counters.go | 6 +++---
examples/atomic-counters/atomic-counters.hash | 4 ++--
examples/atomic-counters/atomic-counters.sh | 11 ++++++-----
public/atomic-counters | 19 ++++++++++---------
4 files changed, 21 insertions(+), 19 deletions(-)
diff --git a/examples/atomic-counters/atomic-counters.go b/examples/atomic-counters/atomic-counters.go
index 5f8a2d7..01d4115 100644
--- a/examples/atomic-counters/atomic-counters.go
+++ b/examples/atomic-counters/atomic-counters.go
@@ -42,8 +42,8 @@ func main() {
// Wait until all the goroutines are done.
wg.Wait()
- // 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'.
+ // Here no goroutines are writing to 'ops', but using
+ // `Load` it's safe to atomically read a value even while
+ // other goroutines are (atomically) updating it.
fmt.Println("ops:", ops.Load())
}
diff --git a/examples/atomic-counters/atomic-counters.hash b/examples/atomic-counters/atomic-counters.hash
index 2e18a61..76cc67c 100644
--- a/examples/atomic-counters/atomic-counters.hash
+++ b/examples/atomic-counters/atomic-counters.hash
@@ -1,2 +1,2 @@
-806f385f4485c3e9d10fe319744dd58ab77adaaf
-LfAMxMppwL-
+3435537238237eb363f652dddb405788fec98c8b
+HWE6h4-y-Fw
diff --git a/examples/atomic-counters/atomic-counters.sh b/examples/atomic-counters/atomic-counters.sh
index 1680a10..4c84d74 100644
--- a/examples/atomic-counters/atomic-counters.sh
+++ b/examples/atomic-counters/atomic-counters.sh
@@ -1,9 +1,10 @@
# We expect to get exactly 50,000 operations. Had we
-# used the non-atomic `ops++` to increment the counter,
-# we'd likely get a different number, changing between
-# runs, because the goroutines would interfere with
-# each other. Moreover, we'd get data race failures
-# when running with the `-race` flag.
+# used a non-atomic integer and incremented it with
+# `ops++`, we'd likely get a different number,
+# changing between runs, because the goroutines
+# would interfere with each other. Moreover, we'd
+# get data race failures when running with the
+# `-race` flag.
$ go run atomic-counters.go
ops: 50000
diff --git a/public/atomic-counters b/public/atomic-counters
index 0bd4299..ac967cc 100644
--- a/public/atomic-counters
+++ b/public/atomic-counters
@@ -46,7 +46,7 @@ counters accessed by multiple goroutines.
- 
+ 
package main
|
@@ -160,9 +160,9 @@ counter exactly 1000 times.
- 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’.
+ Here no goroutines are writing to ‘ops’, but using
+Load it’s safe to atomically read a value even while
+other goroutines are (atomically) updating it.
|
@@ -179,11 +179,12 @@ safe anyway, because no goroutines are writing to ‘ops’.
|
We expect to get exactly 50,000 operations. Had we
-used the non-atomic ops++ to increment the counter,
-we’d likely get a different number, changing between
-runs, because the goroutines would interfere with
-each other. Moreover, we’d get data race failures
-when running with the -race flag.
+used a non-atomic integer and incremented it with
+ops++ , we’d likely get a different number,
+changing between runs, because the goroutines
+would interfere with each other. Moreover, we’d
+get data race failures when running with the
+-race flag.
|
|