It is currently possible to make non-atomic comparisons of atomic
values:
x := atomic.NewInt32(1)
y := atomic.NewInt32(1)
fmt.Println(*x == *y)
This is undesirable because it loads the value in a non-atomic way. The
correct method is,
x := atomic.NewInt32(1)
y := atomic.NewInt32(1)
fmt.Println(x.Load() == y.Load())
To prevent this, disallow comparison of atomic values by embedding an
uncomparable array into atomics. The empty array adds no runtime cost,
and does not increase the in-memory size of the structs. Inspired by
[go4.org/mem#RO][1].
[1]: 3dbcd07079/mem.go (L42)
Note that the Value struct, which embeds `"sync/atomic".Value` was also
changed. This will break usages in the following form, but that's
acceptable because unkeyed struct literals are among the exceptions
stated in the [Go 1 compatibility expectations][2].
import (
syncatomic "sync/atomic"
"go.uber.org/atomic"
)
atomic.Value{syncatomic.Value{..}}
[2]: https://golang.org/doc/go1compat#expectationsResolves#72