Original post

Hi, the atomic.Value doc (https://golang.org/pkg/sync/atomic/) states

Once Store has been called, a Value must not be copied.

A Value must not be copied after first use.

What does that even mean?

Does it just mean that under x := y.Load() the x will not show the atomic behaviour that y enjoys? I’d think this is so obvious that I suspect that statement in the docs mean something else.

Considering the following most basic snippet with an atomic.Value a, strictly without anything “copied”:

if len(a.Load().(string)) == 0 {
  panic("empty string!")


In the above snippet, isn’t the use of atomic.Value completely useless because between the two Load()’s a Store() might occur from somewhere else, setting a to an empty string that would then have bypassed the panic-check?

So what one obviously needs to do is:

x := a.Load().(string)

if len(x) == 0 {
  panic("empty string!")


But beware: x := a.Load().(string) is copying which must not be done… no? I’d say copying must obiviously be done for atomic.Value to have any use.

Can someone please unconfuse me? Thanks.