Skip to content

does len(map) race with map writes? #20615

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

Closed
Codefor opened this issue Jun 8, 2017 · 3 comments
Closed

does len(map) race with map writes? #20615

Codefor opened this issue Jun 8, 2017 · 3 comments

Comments

@Codefor
Copy link

Codefor commented Jun 8, 2017

Please answer these questions before submitting your issue. Thanks!

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

go version go1.8 linux/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/usr/local/go/threeparty"
GORACE="history_size=7"
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-build449371707=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

I've encountered the bellowing situations:

fatal error: concurrent map iteration and map write;
fatal error: concurrent map writes

But does len(map) race with concurrent map writes? and why?

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

What did you expect to see?

What did you see instead?

@ALTree
Copy link
Member

ALTree commented Jun 8, 2017

But does len(map) race with concurrent map writes? and why?

Because a write can change the map size so you have concurrent accesses on the len map attribute and at least one of them is a write, which is the definition of data race.

@ALTree
Copy link
Member

ALTree commented Jun 8, 2017

Also: the Go project does not use its bug tracker for general discussion or asking questions. The Github bug tracker is only used for tracking bugs and proposals going through the Proposal Process. Please see the Questions wiki page; it has a list of good places for asking this kind of questions.

@ALTree ALTree closed this as completed Jun 8, 2017
@bradfitz
Copy link
Contributor

bradfitz commented Jun 8, 2017

Note that the fatal error: concurrent map crashes are best effort. The lack of crash does not mean that you're free of data races. IIRC, len(m) compiles to a single memory load and doesn't take any locks or make any calls (including that fatal crash throw call).

But I think the race detector should detect such problems.

@golang golang locked and limited conversation to collaborators Jun 8, 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

4 participants