aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/race
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2020-01-23 15:02:43 -0800
committerIan Lance Taylor <iant@golang.org>2020-03-20 04:00:36 +0000
commit635a83047b4733f8cb3c9f5ac9d7c057622c2b52 (patch)
tree7689d7371b47f2a8edbc877593a88337ef1d16c4 /src/runtime/race
parent65367df4776a9fcc44c5aebbac994f76a1f4a897 (diff)
downloadgo-635a83047b4733f8cb3c9f5ac9d7c057622c2b52.tar.gz
go-635a83047b4733f8cb3c9f5ac9d7c057622c2b52.zip
runtime/race: test that close synchronizes with read
Add a test to ensure that the race detector sees that closing a channel synchronizes with a read from that channel. This test case failed when CL 181543 was in the tree. CL 181543 was reverted in CL 216158; this adds a test to make sure that we don't re-introduce the problem at a later date. For #32529 For #36714 Change-Id: I5a40f744c67c3f8191d6ad822710c180880a7375 Reviewed-on: https://go-review.googlesource.com/c/go/+/216099 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Diffstat (limited to 'src/runtime/race')
-rw-r--r--src/runtime/race/testdata/chan_test.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/runtime/race/testdata/chan_test.go b/src/runtime/race/testdata/chan_test.go
index 60e55ed66a..3e57b8221c 100644
--- a/src/runtime/race/testdata/chan_test.go
+++ b/src/runtime/race/testdata/chan_test.go
@@ -737,3 +737,29 @@ func TestNoRaceBlockedSelectSendSync(t *testing.T) {
case <-make(chan int):
}
}
+
+// Test that close synchronizes with a read from the empty closed channel.
+// See https://golang.org/issue/36714.
+func TestNoRaceCloseHappensBeforeRead(t *testing.T) {
+ for i := 0; i < 100; i++ {
+ var loc int
+ var write = make(chan struct{})
+ var read = make(chan struct{})
+
+ go func() {
+ select {
+ case <-write:
+ _ = loc
+ default:
+ }
+ close(read)
+ }()
+
+ go func() {
+ loc = 1
+ close(write)
+ }()
+
+ <-read
+ }
+}