From b70c15adaa0983b3d07312f425b8c6d4df71457f Mon Sep 17 00:00:00 2001
From: Eli Bendersky
Date: Thu, 5 Sep 2019 13:26:08 -0700
Subject: [PATCH] Clarify reading op non-atomically
---
examples/atomic-counters/atomic-counters.go | 6 +++++
examples/atomic-counters/atomic-counters.hash | 4 ++--
public/atomic-counters | 24 +++++++++++++++----
3 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/examples/atomic-counters/atomic-counters.go b/examples/atomic-counters/atomic-counters.go
index 2a0901b..046a347 100644
--- a/examples/atomic-counters/atomic-counters.go
+++ b/examples/atomic-counters/atomic-counters.go
@@ -42,5 +42,11 @@ 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`.
fmt.Println("ops:", ops)
}
diff --git a/examples/atomic-counters/atomic-counters.hash b/examples/atomic-counters/atomic-counters.hash
index e35f8f2..989ed19 100644
--- a/examples/atomic-counters/atomic-counters.hash
+++ b/examples/atomic-counters/atomic-counters.hash
@@ -1,2 +1,2 @@
-103c9b7d036e3a5c14dc481755b78b10dc9f894e
-GRkVf6J1--B
+8ebec0be3b167021c96b8b497d0e8c0a2ea99385
+F2pJfduyQiA
diff --git a/public/atomic-counters b/public/atomic-counters
index 6c9d94c..9627c97 100644
--- a/public/atomic-counters
+++ b/public/atomic-counters
@@ -46,7 +46,7 @@ counters accessed by multiple goroutines.
- 
+ 
@@ -162,10 +162,26 @@ address of our ops counter with the
Wait until all the goroutines are done.
|
-
+ |
wg.Wait()
- fmt.Println("ops:", ops)
+
+
+ |
+
+
+
+
+ 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 .
+
+ |
+
+
+ fmt.Println("ops:", ops)
}
@@ -220,7 +236,7 @@ state.
|