diff --git a/examples/atomic-counters/atomic-counters.go b/examples/atomic-counters/atomic-counters.go index 5f8a2d7f4..01d411546 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 2e18a611d..76cc67cb6 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 1680a100c..4c84d742f 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 0bd4299c2..ac967ccdc 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.