Source file
test/fixedbugs/issue19182.go
1
2
3
4
5
6
7
8
9 package main
10
11 import (
12 "fmt"
13 "runtime"
14 "sync/atomic"
15 "time"
16 )
17
18 var a uint64 = 0
19
20 func main() {
21 runtime.GOMAXPROCS(2)
22
23 go func() {
24 for {
25 atomic.AddUint64(&a, uint64(1))
26 }
27 }()
28
29 time.Sleep(10 * time.Millisecond)
30 i, val := 0, atomic.LoadUint64(&a)
31 for ; val == 0 && i < 100; val, i = atomic.LoadUint64(&a), i+1 {
32 time.Sleep(100 * time.Millisecond)
33 }
34 if val == 0 {
35 fmt.Printf("Failed to observe atomic increment after %d tries\n", i)
36 }
37
38 }
39
View as plain text