Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How did I fix this error when run "go vet ":direct assignment to atomic value? #21942

Closed
luopengift opened this issue Sep 20, 2017 · 1 comment

Comments

@luopengift
Copy link

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.9 linux/amd64

Does this issue reproduce with the latest release?

YES.

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN="/usr/local/go/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/data/golang"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build249019464=/tmp/go-build"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

This is a sample program,saved as myatomic.go, here is source code:

package main

import (
	"fmt"
	"sync/atomic"
)

func main() {
	var i uint64 = 0
	i = atomic.AddUint64(&i, 1)
	fmt.Println(i)
}

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
https://play.golang.org/p/xpk5Y8iFuN

What did you expect to see?

I wish know how I fix "direct assignment to atomic value".
Thanks very much.

What did you see instead?

I run it with command:go run myatomic.go, then return 1 to me. It's ok.
BUT, when command is go vet myatomic.go, it runs error.
Here is console detail:

[root@iZm5egf7xb48axmu4z1t3fZ GoTestExample]# go run myatomic.go 
1
[root@iZm5egf7xb48axmu4z1t3fZ GoTestExample]# go vet myatomic.go 
myatomic.go:10: direct assignment to atomic value
exit status 1

Besh wishs!~

@mvdan
Copy link
Member

mvdan commented Sep 20, 2017

For questions about Go, see https://golang.org/wiki/Questions.

@mvdan mvdan closed this as completed Sep 20, 2017
@golang golang locked and limited conversation to collaborators Sep 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants