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.
package main
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)
}