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

io/ioutil: data race on rand #4212

Closed
dvyukov opened this issue Oct 8, 2012 · 4 comments
Closed

io/ioutil: data race on rand #4212

dvyukov opened this issue Oct 8, 2012 · 4 comments
Milestone

Comments

@dvyukov
Copy link
Member

dvyukov commented Oct 8, 2012

parent: 14564:3350c94fe6b7 tip

test$ go run -race run.go

WARNING: DATA RACE
Read by goroutine 4:
  io/ioutil.nextSuffix()
      /usr/local/google/home/dvyukov/go_prefetch/src/pkg/io/ioutil/tempfile.go:25 +0x2d
  io/ioutil.TempDir()
      /usr/local/google/home/dvyukov/go_prefetch/src/pkg/io/ioutil/tempfile.go:77 +0xad
  main.(*test).makeTempDir()
      /usr/local/google/home/dvyukov/go_prefetch/test/run.go:496 +0x41
  main.(*test).run()
      /usr/local/google/home/dvyukov/go_prefetch/test/run.go:323 +0x74a
  main.func·001()
      /usr/local/google/home/dvyukov/go_prefetch/test/run.go:233 +0x3a

Previous write by goroutine 3:
  io/ioutil.nextSuffix()
      /usr/local/google/home/dvyukov/go_prefetch/src/pkg/io/ioutil/tempfile.go:30 +0x64
  io/ioutil.TempDir()
      /usr/local/google/home/dvyukov/go_prefetch/src/pkg/io/ioutil/tempfile.go:77 +0xad
  main.(*test).makeTempDir()
      /usr/local/google/home/dvyukov/go_prefetch/test/run.go:496 +0x41
  main.(*test).run()
      /usr/local/google/home/dvyukov/go_prefetch/test/run.go:323 +0x74a
  main.func·001()
      /usr/local/google/home/dvyukov/go_prefetch/test/run.go:233 +0x3a

Goroutine 4 (running) created at:
  main.runTests()
      /usr/local/google/home/dvyukov/go_prefetch/test/run.go:235 +0xc6

Goroutine 3 (running) created at:
  main.runTests()
      /usr/local/google/home/dvyukov/go_prefetch/test/run.go:235 +0xc6

This can break badly under gccgo:

var rand uint32
func nextSuffix() string {
        r := rand
        if r == 0 {
                r = reseed()
        }
        r = r*1664525 + 1013904223 // constants from Numerical Recipes
        rand = r
        return strconv.Itoa(int(1e9 + r%1e9))[1:]
}
@rsc
Copy link
Contributor

rsc commented Oct 9, 2012

Comment 1:

I guess it should have a lock. Sigh.

Status changed to Accepted.

@dvyukov
Copy link
Member Author

dvyukov commented Oct 9, 2012

Comment 2:

It may have atomic ops (CAS-loop).

@rsc
Copy link
Contributor

rsc commented Oct 9, 2012

Comment 3:

A lock is fine. It's about to do file i/o so speed is not necessary.

@dvyukov
Copy link
Member Author

dvyukov commented Oct 9, 2012

Comment 4:

This issue was closed by revision 49a5c28.

Status changed to Fixed.

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1maybe label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
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