Skip to content

Commit

Permalink
Small comment updates to atomic-counters
Browse files Browse the repository at this point in the history
  • Loading branch information
eliben committed Oct 2, 2023
1 parent d1ca2ce commit edab962
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
6 changes: 3 additions & 3 deletions examples/atomic-counters/atomic-counters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
4 changes: 2 additions & 2 deletions examples/atomic-counters/atomic-counters.hash
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
806f385f4485c3e9d10fe319744dd58ab77adaaf
LfAMxMppwL-
3435537238237eb363f652dddb405788fec98c8b
HWE6h4-y-Fw
11 changes: 6 additions & 5 deletions examples/atomic-counters/atomic-counters.sh
Original file line number Diff line number Diff line change
@@ -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

Expand Down
19 changes: 10 additions & 9 deletions public/atomic-counters

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit edab962

Please sign in to comment.