Add sleep in atomic-counter to make it run ~1 time/ms #129

Open
wants to merge 1 commit into
from

1 participant

@aaronbbrown

As written, the atomic-counter example runs in a tight loop, saturating all CPU cores and returning a very high value:

$ go run atomic-counters.go
ops: 5159303

The comment mentions running approximately, once a millisecond for which the code has no such constraint. I added an explicit time.Sleep(time.Millisecond) here and now the correct value is returned:

$ go run atomic-counters.go
ops: 40350

@mmcgrana thanks so much for building this. It has been a great introduction to Go for me! 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment