aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/race/testdata
diff options
context:
space:
mode:
authorKeith Randall <khr@google.com>2018-09-17 12:25:36 -0700
committerKeith Randall <khr@golang.org>2018-09-18 17:28:37 +0000
commit83dfc3b001245f0b725afdc94c0b540fe1952d21 (patch)
tree98e163cfa41ec69883528ab967be4beb1bceeb39 /src/runtime/race/testdata
parent77f9b2728eb08456899e6500328e00ec4829dddf (diff)
downloadgo-83dfc3b001245f0b725afdc94c0b540fe1952d21.tar.xz
runtime: ignore races between close and len/cap
They aren't really races, or at least they don't have any observable effect. The spec is silent on whether these are actually races or not. Fix this problem by not using the address of len (or of cap) as the location where channel operations are recorded to occur. Use a random other field of hchan for that. I'm not 100% sure we should in fact fix this. Opinions welcome. Fixes #27070 Change-Id: Ib4efd4b62e0d1ef32fa51e373035ef207a655084 Reviewed-on: https://go-review.googlesource.com/135698 Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
Diffstat (limited to 'src/runtime/race/testdata')
-rw-r--r--src/runtime/race/testdata/chan_test.go30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/runtime/race/testdata/chan_test.go b/src/runtime/race/testdata/chan_test.go
index 7f349c42ed..60e55ed66a 100644
--- a/src/runtime/race/testdata/chan_test.go
+++ b/src/runtime/race/testdata/chan_test.go
@@ -577,18 +577,32 @@ func TestRaceChanItselfCap(t *testing.T) {
<-compl
}
-func TestRaceChanCloseLen(t *testing.T) {
- v := 0
- _ = v
+func TestNoRaceChanCloseLen(t *testing.T) {
c := make(chan int, 10)
- c <- 0
+ r := make(chan int, 10)
+ go func() {
+ r <- len(c)
+ }()
go func() {
- v = 1
close(c)
+ r <- 0
}()
- time.Sleep(1e7)
- _ = len(c)
- v = 2
+ <-r
+ <-r
+}
+
+func TestNoRaceChanCloseCap(t *testing.T) {
+ c := make(chan int, 10)
+ r := make(chan int, 10)
+ go func() {
+ r <- cap(c)
+ }()
+ go func() {
+ close(c)
+ r <- 0
+ }()
+ <-r
+ <-r
}
func TestRaceChanCloseSend(t *testing.T) {