diff --git a/examples/atomic-counters/atomic-counters.go b/examples/atomic-counters/atomic-counters.go index 19ee445..842dfee 100644 --- a/examples/atomic-counters/atomic-counters.go +++ b/examples/atomic-counters/atomic-counters.go @@ -23,14 +23,14 @@ func main() { // once a millisecond. for i := 0; i < 50; i++ { go func() { - for { + for { // To atomically increment the counter we // use `AddUint64`, giving it the memory // address of our `ops` counter with the // `&` syntax. atomic.AddUint64(&ops, 1) - // Allow other goroutines to proceed. + // Allow other goroutines to proceed. runtime.Gosched() } }() diff --git a/public/atomic-counters b/public/atomic-counters index 0139cb8..1102b1e 100644 --- a/public/atomic-counters +++ b/public/atomic-counters @@ -57,6 +57,7 @@ counters accessed by multiple goroutines.

import "fmt"
 import "time"
 import "sync/atomic"
+import "runtime"
 
@@ -97,7 +98,6 @@ once a millisecond.

    for i := 0; i < 50; i++ {
         go func() {
             for {
-                time.Sleep(time.Millisecond)
 
@@ -113,6 +113,18 @@ address of our ops counter with the
                atomic.AddUint64(&ops, 1)
+
+ + + + + + +

Allow other goroutines to proceed.

+ + + +
                runtime.Gosched()
             }
         }()
     }