]> Cypherpunks repositories - gostls13.git/commitdiff
io/ioutil: fix data race under the race detector
authorDmitriy Vyukov <dvyukov@google.com>
Sun, 7 Oct 2012 18:08:06 +0000 (22:08 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Sun, 7 Oct 2012 18:08:06 +0000 (22:08 +0400)
See issue 3970 (it's already marked as Fixed).

R=rsc, minux.ma
CC=golang-dev
https://golang.org/cl/6624059

src/pkg/io/ioutil/blackhole.go [new file with mode: 0644]
src/pkg/io/ioutil/blackhole_race.go [new file with mode: 0644]
src/pkg/io/ioutil/ioutil.go

diff --git a/src/pkg/io/ioutil/blackhole.go b/src/pkg/io/ioutil/blackhole.go
new file mode 100644 (file)
index 0000000..c127bdb
--- /dev/null
@@ -0,0 +1,13 @@
+// Copyright 2012 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build !race
+
+package ioutil
+
+var blackHoleBuf = make([]byte, 8192)
+
+func blackHole() []byte {
+       return blackHoleBuf
+}
diff --git a/src/pkg/io/ioutil/blackhole_race.go b/src/pkg/io/ioutil/blackhole_race.go
new file mode 100644 (file)
index 0000000..eb640e0
--- /dev/null
@@ -0,0 +1,13 @@
+// Copyright 2012 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build race
+
+package ioutil
+
+// Replaces the normal fast implementation with slower but formally correct one.
+
+func blackHole() []byte {
+       return make([]byte, 8192)
+}
index f072b8c754a53f14fafedfc4214c35385d4fa909..31c77299eeef7bc6a1d42d100a6af23644a89bb1 100644 (file)
@@ -130,12 +130,11 @@ func (devNull) Write(p []byte) (int, error) {
        return len(p), nil
 }
 
-var blackHole = make([]byte, 8192)
-
 func (devNull) ReadFrom(r io.Reader) (n int64, err error) {
+       buf := blackHole()
        readSize := 0
        for {
-               readSize, err = r.Read(blackHole)
+               readSize, err = r.Read(buf)
                n += int64(readSize)
                if err != nil {
                        if err == io.EOF {